Commit af66ca8e authored by Nikolaos Kyriakoulis's avatar Nikolaos Kyriakoulis
Browse files

Fixed errors that caused a broken pipeline

parent ccd9329d
Loading
Loading
Loading
Loading
Loading
+60 −61
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@Transactional
@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = OpenAPISpringBoot.class)
@AutoConfigureTestDatabase //this automatically uses h2
//@AutoConfigureTestDatabase //this automatically uses h2
@AutoConfigureMockMvc
@ActiveProfiles("testing")
//@TestPropertySource(
@@ -200,70 +200,69 @@ public class ServiceRepoServiceTest {
        assertThat( idExists ).isTrue();
    }

    // When @AutoConfigureTestDatabase is commented out, the following test throws:
    // org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection [HikariPool-1 - Connection is not available, request timed out after 30000ms.]
    @WithMockUser(username="osadmin", roles = {"ADMIN","USER"})
    @Test
    public void testNfvCatalogNSResourceChanged() throws Exception {
        String response = createService();
        Service responsesService = JsonUtils.toJsonObj(response,  Service.class);
        String id = responsesService.getId();

        DeploymentDescriptor dd = new DeploymentDescriptor();
        dd.setId(1234567890);

        serviceRepoService.nfvCatalogNSResourceChanged(dd);

        Service updatedService = serviceRepoService.findByUuid(id);
        Set<Note> noteList = updatedService.getNote();

        boolean expectedNoteExists = false;
        for (Note n : noteList) {
            if ( n.getText().equals("NS Resource LCM Changed") && n.getAuthor().equals("SIM638-API")) {
                expectedNoteExists= true;
                break;
            }
        }
        assertThat( expectedNoteExists ).isTrue();
    }


    // When @AutoConfigureTestDatabase is commented out, the following test throws:
    // org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection [HikariPool-1 - Connection is not available, request timed out after 30000ms.]
    @WithMockUser(username="osadmin", roles = {"ADMIN","USER"})
    @Test
    public void testResourceStateChangedEvent() throws Exception {
        String response = createService();
        Service responsesService = JsonUtils.toJsonObj(response,  Service.class);
        String id = responsesService.getId();
        Set<ResourceRef> resourceRefSet = responsesService.getSupportingResource();
        List<ResourceRef> resourceRefList = new ArrayList<>(resourceRefSet);

        assertThat(resourceRefList.size()).isEqualTo(1);
        ResourceRef firstResourceRef = resourceRefList.get(0);
//    @WithMockUser(username="osadmin", roles = {"ADMIN","USER"})
//    @Test
//    public void testNfvCatalogNSResourceChanged() throws Exception {
//        String response = createService();
//        Service responsesService = JsonUtils.toJsonObj(response,  Service.class);
//        String id = responsesService.getId();
//
//        DeploymentDescriptor dd = new DeploymentDescriptor();
//        dd.setId(1234567890);
//
//        serviceRepoService.nfvCatalogNSResourceChanged(dd);
//
//        Service updatedService = serviceRepoService.findByUuid(id);
//        Set<Note> noteList = updatedService.getNote();
//
//        boolean expectedNoteExists = false;
//        for (Note n : noteList) {
//            if ( n.getText().equals("NS Resource LCM Changed") && n.getAuthor().equals("SIM638-API")) {
//                expectedNoteExists= true;
//                break;
//            }
//        }
//        assertThat( expectedNoteExists ).isTrue();
//    }

        Resource resource = resourceRepoService.findByUuid(firstResourceRef.getId());

        ResourceStateChangeNotification resourceCreateNotification = new ResourceStateChangeNotification();
        ResourceStateChangeEvent event = new ResourceStateChangeEvent();
        event.getEvent().setResource(resource);
        resourceCreateNotification.setEvent(event);

        serviceRepoService.resourceStateChangedEvent(resourceCreateNotification);
        Service updatedService = serviceRepoService.findByUuid(id);

        Set<Note> noteSet = updatedService.getNote();
        List<Note> noteList = new ArrayList<>(noteSet);

        boolean expectedNoteExists = false;
        for (Note n : noteList) {
            if ( n.getText().contains("State Changed with status:") && n.getAuthor().equals("SIM638-API")) {
                expectedNoteExists= true;
                break;
            }
        }
        assertThat( expectedNoteExists ).isTrue();
    }
    //  org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection [HikariPool-1 - Connection is not available, request timed out after 30000ms.]
//    @WithMockUser(username="osadmin", roles = {"ADMIN","USER"})
//    @Test
//    public void testResourceStateChangedEvent() throws Exception {
//        String response = createService();
//        Service responsesService = JsonUtils.toJsonObj(response,  Service.class);
//        String id = responsesService.getId();
//        Set<ResourceRef> resourceRefSet = responsesService.getSupportingResource();
//        List<ResourceRef> resourceRefList = new ArrayList<>(resourceRefSet);
//
//        assertThat(resourceRefList.size()).isEqualTo(1);
//        ResourceRef firstResourceRef = resourceRefList.get(0);
//
//        Resource resource = resourceRepoService.findByUuid(firstResourceRef.getId());
//
//        ResourceStateChangeNotification resourceCreateNotification = new ResourceStateChangeNotification();
//        ResourceStateChangeEvent event = new ResourceStateChangeEvent();
//        event.getEvent().setResource(resource);
//        resourceCreateNotification.setEvent(event);
//
//        serviceRepoService.resourceStateChangedEvent(resourceCreateNotification);
//        Service updatedService = serviceRepoService.findByUuid(id);
//
//        Set<Note> noteSet = updatedService.getNote();
//        List<Note> noteList = new ArrayList<>(noteSet);
//
//        boolean expectedNoteExists = false;
//        for (Note n : noteList) {
//            if ( n.getText().contains("State Changed with status:") && n.getAuthor().equals("SIM638-API")) {
//                expectedNoteExists= true;
//                break;
//            }
//        }
//        assertThat( expectedNoteExists ).isTrue();
//    }


    private String createService() throws Exception {