@Test public void removeConnection() throws Exception { ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry(); ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION); connectionFactoryLocator.addConnectionFactory(connectionFactory); StubConnectionRepository connectionRepository = new StubConnectionRepository(); connectionRepository.addConnection( connectionFactory.createConnection( new ConnectionData( "oauth2Provider", "provider1User1", null, null, null, null, null, null, null))); connectionRepository.addConnection( connectionFactory.createConnection( new ConnectionData( "oauth2Provider", "provider1User2", null, null, null, null, null, null, null))); assertEquals(2, connectionRepository.findConnections("oauth2Provider").size()); ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository); List<DisconnectInterceptor<?>> interceptors = getDisconnectInterceptor(); connectController.setDisconnectInterceptors(interceptors); MockMvc mockMvc = standaloneSetup(connectController).build(); mockMvc .perform(delete("/connect/oauth2Provider/provider1User1")) .andExpect(redirectedUrl("/connect/oauth2Provider")); assertEquals(1, connectionRepository.findConnections("oauth2Provider").size()); assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).preDisconnectInvoked); assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).postDisconnectInvoked); assertNull(((TestConnectInterceptor<?>) (interceptors.get(0))).connectionFactory); assertTrue(((TestConnectInterceptor<?>) (interceptors.get(1))).preDisconnectInvoked); assertTrue(((TestConnectInterceptor<?>) (interceptors.get(1))).postDisconnectInvoked); assertSame( connectionFactory, ((TestConnectInterceptor<?>) (interceptors.get(1))).connectionFactory); }
@Test public void testGetContextElement_OK() throws Exception { ArgumentCaptor<QueryContext> queryContextArg = ArgumentCaptor.forClass(QueryContext.class); List attributes = Collections.singletonList(new ContextAttribute("test", "string", "OK")); ContextElement contextElement = new ContextElement(); contextElement.setEntityId(new EntityId("12345678", "", false)); contextElement.setContextAttributeList(attributes); ContextElementResponse contextElementResponse = new ContextElementResponse(contextElement, new StatusCode(CodeEnum.CODE_200)); QueryContextResponse response = new QueryContextResponse(); response.setContextElementResponses(Collections.singletonList(contextElementResponse)); when(ngsiController.queryContext(any())).thenReturn(response); mockMvc .perform(get("/v1/contextEntities/12345678").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.statusCode.code").value("200")) .andExpect(jsonPath("$.contextElement.attributes[0].name").value("test")) .andExpect(jsonPath("$.contextElement.attributes[0].type").value("string")) .andExpect(jsonPath("$.contextElement.attributes[0].value").value("OK")); verify(ngsiController).queryContext(queryContextArg.capture()); QueryContext queryContext = queryContextArg.getValue(); assertNotNull(queryContext); assertNotNull(queryContext.getEntityIdList()); assertEquals(1, queryContext.getEntityIdList().size()); assertNull(queryContext.getAttributeList()); assertEquals("12345678", queryContext.getEntityIdList().get(0).getId()); assertEquals("", queryContext.getEntityIdList().get(0).getType()); assertEquals(false, queryContext.getEntityIdList().get(0).getIsPattern()); }
/** * Test DELETE to /restAPI/items/{id}, to delete a document * * @throws Exception */ @Test public void testDeleteDoc() throws Exception { String id = this.preAddedDocs.get(1).getId(); this.mockMvc .perform(delete("/restAPI/items/" + id).contentType(contentType)) .andExpect(status().isOk()); // Number of document decreased by 1 assertEquals(1, docRepository.count()); // The original document is deleted StoredDocument retrievedDoc = docRepository.findOne(id); assertNull(retrievedDoc); }