X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ves-nf-oam-adopter%2Fves-nf-oam-adopter-app%2Fsrc%2Ftest%2Fjava%2Forg%2Fo%2Fran%2Foam%2Fnf%2Foam%2Fadopter%2Fapp%2FAdapterApplicationTest.java;h=78d036c920a6c44c6b37378b8db8218f22a7822d;hb=723c84531a12d8ceff53444a7cdb37589f6e32ad;hp=3b9cdf39763b3f2c564e1e4cf3fab623f6d41d2b;hpb=cbc3da1f8c19847297e2ad88ba4f70210605b59e;p=oam%2Fnf-oam-adopter.git diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-app/src/test/java/org/o/ran/oam/nf/oam/adopter/app/AdapterApplicationTest.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-app/src/test/java/org/o/ran/oam/nf/oam/adopter/app/AdapterApplicationTest.java index 3b9cdf3..78d036c 100644 --- a/ves-nf-oam-adopter/ves-nf-oam-adopter-app/src/test/java/org/o/ran/oam/nf/oam/adopter/app/AdapterApplicationTest.java +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-app/src/test/java/org/o/ran/oam/nf/oam/adopter/app/AdapterApplicationTest.java @@ -82,32 +82,40 @@ class AdapterApplicationTest { @Test @WithMockUser(username = "admin", roles = "ADMIN") - public void testGetAllAdapters() throws Exception { + void testGetAllAdapters() throws Exception { when(deployer.getAll()).thenReturn(Collections.singletonList("mockResult")); - mockMvc.perform(get("/adapters/").secure(true).contentType(MediaType.APPLICATION_JSON)).andDo(print()) + mockMvc.perform(get("/adapters/").secure(true) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) .andExpect(status().isOk()).andExpect(content().string(containsString("mockResult"))); } @Test @WithMockUser(username = "admin", roles = "ADMIN") - public void testDeleteAdapter() throws Exception { - mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true).contentType(MediaType.APPLICATION_JSON)) + void testDeleteAdapter() throws Exception { + mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true) + .contentType(MediaType.APPLICATION_JSON)) .andDo(print()).andExpect(status().isOk()); } @Test @WithMockUser(username = "admin", roles = "ADMIN") - public void testNotFound() throws Exception { - doThrow(NotFoundException.class).when(deployer).delete(anyString()); - - mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true).contentType(MediaType.APPLICATION_JSON)) - .andDo(print()).andExpect(status().isNotFound()); + void testNotFound() throws Exception { + doThrow(new NotFoundException("172.10.55.3")) + .when(deployer) + .delete(anyString()); + + mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isNotFound()) + .andExpect(content().string(containsString("Adapter 172.10.55.3 is not present."))); } @Test @WithMockUser(username = "admin", roles = "ADMIN") - public void testAddAdapter() throws Exception { + void testAddAdapter() throws Exception { final Adapter adapter = new Adapter(); adapter.setHost("172.10.55.3"); @@ -117,14 +125,16 @@ class AdapterApplicationTest { mechId.password("somePass"); adapter.setMechId(mechId); - mockMvc.perform(post("/adapters/adapter").secure(true).contentType(MediaType.APPLICATION_JSON) - .content(GSON.toJson(adapter))).andDo(print()).andExpect(status().isOk()); + mockMvc.perform(post("/adapters/adapter").secure(true) + .contentType(MediaType.APPLICATION_JSON) + .content(GSON.toJson(adapter))) + .andDo(print()) + .andExpect(status().isOk()); } @Test @WithMockUser(username = "admin", roles = "ADMIN") - public void testAlreadyExist() throws Exception { - + void testAlreadyExist() throws Exception { final Adapter adapter = new Adapter(); adapter.setHost("172.10.55.3"); @@ -133,16 +143,20 @@ class AdapterApplicationTest { mechId.password("somePass"); adapter.setMechId(mechId); - doThrow(AlreadyPresentException.class).when(deployer).create(anyString(), anyString(), anyString()); + doThrow(new AlreadyPresentException("172.10.55.3")) + .when(deployer).create(anyString(), anyString(), anyString()); - mockMvc.perform(post("/adapters/adapter").secure(true).contentType(MediaType.APPLICATION_JSON) - .content(GSON.toJson(adapter))).andDo(print()).andExpect(status().isBadRequest()); + mockMvc.perform(post("/adapters/adapter") + .secure(true).contentType(MediaType.APPLICATION_JSON) + .content(GSON.toJson(adapter))) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(content().string(containsString("Adapter 172.10.55.3 already present."))); } @Test @WithMockUser(username = "admin", roles = "ADMIN") - public void testMissingArguments() throws Exception { - + void testMissingArguments() throws Exception { final Adapter adapter = new Adapter(); adapter.setHost("172.10.55.3"); @@ -150,13 +164,31 @@ class AdapterApplicationTest { mechId.username("admin"); adapter.setMechId(mechId); + mockMvc.perform(post("/adapters/adapter").secure(true) + .contentType(MediaType.APPLICATION_JSON) + .content(GSON.toJson(adapter))) + .andDo(print()) + .andExpect(status().isBadRequest()); + } + + @Test + void testUnauthorized() throws Exception { + mockMvc.perform(post("/adapters/adapter").secure(true)) + .andDo(print()) + .andExpect(status().isUnauthorized()); + + mockMvc.perform(post("/adapters/adapter").secure(true)) + .andDo(print()) + .andExpect(status().isUnauthorized()); + + mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true)) + .andDo(print()) + .andExpect(status().isUnauthorized()); - mockMvc.perform(post("/adapters/adapter").secure(true).contentType(MediaType.APPLICATION_JSON) - .content(GSON.toJson(adapter))).andDo(print()).andExpect(status().isBadRequest()); } @Test - public void test() { + void test() { final ZoneId zoneId = ZoneId.of("+02:00"); when(deployer.getTimeZone("172.10.55.3")).thenReturn(zoneId); assertEquals(zoneId, timeZoneServiceProvider.getTimeZone("172.10.55.3"));