@Test public void testAddWorkspace() { int startingVertexCount = graph.getAllVertices().size(); int startingEdgeCount = graph.getAllEdges().size(); String workspaceId = "testWorkspaceId"; idGenerator.push(workspaceId); idGenerator.push(workspaceId + "_to_" + user1.getUserId()); Workspace workspace = workspaceRepository.add("workspace1", user1); assertTrue( authorizationRepository .getGraphAuthorizations() .contains(WorkspaceRepository.WORKSPACE_ID_PREFIX + workspaceId)); assertEquals( startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex assertEquals( startingEdgeCount + 1, graph.getAllEdges().size()); // +1 = the edge between workspace and user1 assertNull( "Should not have access", graph.getVertex(workspace.getId(), new InMemoryAuthorizations())); InMemoryAuthorizations authorizations = new InMemoryAuthorizations(WorkspaceRepository.VISIBILITY_STRING, workspace.getId()); assertNotNull("Should have access", graph.getVertex(workspace.getId(), authorizations)); Workspace foundWorkspace = workspaceRepository.findById(workspace.getId(), user1); assertEquals(workspace.getId(), foundWorkspace.getId()); }
@Test public void shouldRemoveAllStubbing() throws Exception { when(mock.objectReturningMethod(isA(Integer.class))).thenReturn(100); when(mock.objectReturningMethod(200)).thenReturn(200); reset(mock); assertNull(mock.objectReturningMethod(200)); assertEquals("default behavior should return null", null, mock.objectReturningMethod("blah")); }
@Test public void testCertificationGetters() { Certification credential = CredentialFactory.getInstance().createCertification(); credential.getCertificationType().setId(1L); action.setCredential(new Degree()); assertNull(action.getCertification()); action.setCertification(new Certification()); when(mockDataService.getPersistentObject(CertificationType.class, null)).thenReturn(null); when(mockDataService.getPersistentObject(CertificationType.class, 1L)) .thenReturn(credential.getCertificationType()); action.setCertificationTypeId(null); assertNull(action.getCertificationTypeId()); action.setCertificationTypeId(1L); assertEquals(Long.valueOf(1L), action.getCertificationTypeId()); }
@Test public void when_token_response_contain_null_scope_return_null_as_scope() throws Exception { // GIVEN String tokenContent = "{\"tokenType\":\"599\"," + "\"accessToken\":\"da96c8141bcda91be65db4adbc8fafe77d116c88caacb8de404c0654c16c6620\"," + "\"expiresIn\":\"Bearer\",\"userId\":null," + "\"refreshToken\":\"cb2e2e068447913d0c97f79f888f6e2882bfcb569325a9ad9e9b52937b06e547\"}"; // WHEN String tokenScope = AccessTokenValidator.extractTokenScope(tokenContent); // THEN assertNull(tokenScope); }
@Test public void assertGetUnknownWorkspaceReturnsNull() throws Exception { when(server.execute(isA(MaskedArgumentListBuilder.class))).thenReturn(new StringReader("")); Workspaces workspaces = new Workspaces(server); assertNull("The unknown workspace was not null", workspaces.getWorkspace("name1")); }