diff --git a/src/test/java/portal/api/InMemoryDBIntegrationTest.java b/src/test/java/portal/api/InMemoryDBIntegrationTest.java index 7140307c6c316588c1397dc6fc08a4b102e231e5..79f841ec27f7ddddea03bd2fbda45df04073f2ea 100644 --- a/src/test/java/portal/api/InMemoryDBIntegrationTest.java +++ b/src/test/java/portal/api/InMemoryDBIntegrationTest.java @@ -20,36 +20,21 @@ package portal.api; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; - +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.etsi.osl.model.nfv.*; +import org.junit.Ignore; import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockMultipartFile; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; @@ -60,41 +45,38 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.transaction.annotation.Transactional; +import portal.api.mano.MANOController; +import portal.api.service.*; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; -import org.etsi.osl.model.nfv.DeploymentDescriptor; -import org.etsi.osl.model.nfv.ExperimentMetadata; -import org.etsi.osl.model.nfv.Infrastructure; -import org.etsi.osl.model.nfv.UserSession; -import org.etsi.osl.model.nfv.VxFMetadata; -import portal.api.mano.MANOController; -import portal.api.service.CategoryService; -import portal.api.service.DeploymentDescriptorService; -import portal.api.service.InfrastructureService; -import portal.api.service.ManoPlatformService; -import portal.api.service.ManoProviderService; -import portal.api.service.NSDOBDService; -import portal.api.service.NSDService; -import portal.api.service.PortalPropertiesService; -import portal.api.service.ProductService; -import portal.api.service.UsersService; -import portal.api.service.VFImageService; -import portal.api.service.VxFOBDService; -import portal.api.service.VxFService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @RunWith(SpringRunner.class) @Transactional -@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.MOCK , classes = PortalApplication.class) +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.MOCK , + classes = PortalApplication.class +) //@AutoConfigureTestDatabase -@AutoConfigureMockMvc +@AutoConfigureMockMvc @ActiveProfiles("testing") -@TestPropertySource(properties = {"spring.cloud.consul.config.enabled=false", - "spring.cloud.bus.enabled=false", - "spring.cloud.discovery.enabled=false", - "spring.cloud.consul.enabled=false"}) +@TestPropertySource( + properties ={ + "spring.cloud.consul.config.enabled=false", + "spring.cloud.bus.enabled=false", + "spring.cloud.discovery.enabled=false", + "spring.cloud.consul.enabled=false" + } +) + @@ -102,7 +84,7 @@ public class InMemoryDBIntegrationTest { private static final transient Log logger = LogFactory.getLog( InMemoryDBIntegrationTest.class.getName()); - + @Autowired private MockMvc mvc; @@ -146,9 +128,9 @@ public class InMemoryDBIntegrationTest { @Autowired DeploymentDescriptorService deploymentDescriptorService; - - - + + + @Test public void whenFindByName_thenReturnVxF() { // given @@ -156,14 +138,14 @@ public class InMemoryDBIntegrationTest { VxFMetadata vxf = new VxFMetadata(); vxf.setName("aTestVxF"); vxfService.updateProductInfo(vxf); - + // when VxFMetadata found = vxfService.getVxFByName(vxf.getName()); - + // then assertThat(found.getName()).isEqualTo( vxf.getName() ); } - + @Test public void countDefaultProperties() { assertThat( propsService.getProperties().size() ) @@ -181,28 +163,18 @@ public class InMemoryDBIntegrationTest { */ mvc.perform(get("/admin/users") .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().is(401) ); - + UserSession pu = new UserSession(); pu.setUsername("admin"); pu.setPassword("changeme"); - + // /** // * auth // */ -// HttpSession session = mvc.perform(post("/sessions") -// .with( SecurityMockMvcRequestPostProcessors.csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content( toJson( pu ) )) -// .andExpect(status().isOk()) -// .andExpect(content() -// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("username", is("admin"))) -// .andReturn().getRequest().getSession(); - - + usersService.addPortalUserToUsersFromAuthServer("osadmin", "admin@admin.com", "First", "Last"); mvc.perform(get("/categories") .with( SecurityMockMvcRequestPostProcessors.csrf()) @@ -212,397 +184,398 @@ public class InMemoryDBIntegrationTest { .andExpect(content() .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect( jsonPath("$[0].name", is("None")) ); - - + + /** * with auth session */ mvc.perform(get("/admin/categories") .with( SecurityMockMvcRequestPostProcessors.csrf()) .with( SecurityMockMvcRequestPostProcessors.user("osadmin").roles("ADMIN") ) - .contentType(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) .andExpect(content() .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect( jsonPath("$[0].name", is("None")) ); } - + static byte[] toJson(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsBytes(object); } - + static T toJsonObj(String content, Class valueType) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.readValue( content, valueType); } - - @WithMockUser(username="admin", roles = {"ADMIN","USER"}) - @Test - public void addVxF() throws Exception { - - UserSession pu = new UserSession(); - pu.setUsername("admin"); - pu.setPassword("changeme"); - -// /** -// * auth -// */ -// HttpSession session = mvc.perform(post("/sessions") +// @WithMockUser(username="admin", roles = {"ADMIN","USER"}) +// @Test +// public void addVxF() throws Exception { +// +// UserSession pu = new UserSession(); +// pu.setUsername("admin"); +// pu.setPassword("changeme"); +// usersService.addPortalUserToUsersFromAuthServer("admin", "admin@admin.com", "First", "Last"); +// +//// /** +//// * auth +//// */ +//// HttpSession session = mvc.perform(post("/sessions") +//// .with( SecurityMockMvcRequestPostProcessors.csrf()) +//// .contentType(MediaType.APPLICATION_JSON) +//// .content( toJson( pu ) )) +//// .andExpect(status().isOk()) +//// .andExpect(content() +//// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +//// .andExpect(jsonPath("username", is("admin"))) +//// .andReturn().getRequest().getSession(); +// +// +// +// +// File vxfFile = new File( "src/test/resources/testvxf.txt" ); +// InputStream in = new FileInputStream( vxfFile ); +// String resvxf = IOUtils.toString(in, "UTF-8"); +// logger.info( "resvxf ========> " + resvxf ); +// +// File gz = new File( "src/test/resources/cirros_vnf.tar.gz" ); +// InputStream ing = new FileInputStream( gz ); +// MockMultipartFile prodFile = new MockMultipartFile("prodFile", "cirros_vnf.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); +// +// +//// Map sessionAttributes = new HashMap<>(); +//// Enumeration attr = session.getAttributeNames(); +//// while ( attr.hasMoreElements()) { +//// String aname = attr.nextElement(); +//// System.out.println("aname is: " + aname); +//// System.out.println("Value is: " + session.getAttribute(aname)); +//// sessionAttributes.put(aname, session.getAttribute(aname)); +//// } +// +// +// +// +// MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = +// (MockMultipartHttpServletRequestBuilder) multipart("/admin/vxfs") +// .with( SecurityMockMvcRequestPostProcessors.csrf()) +// .with( SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN") ) ; +// +// mockMultipartHttpServletRequestBuilder.file( prodFile ); +// mockMultipartHttpServletRequestBuilder.param("vxf", resvxf); +// +// mvc.perform(mockMultipartHttpServletRequestBuilder).andExpect(status().isOk()); +// +//// mvc.perform(MockMvcRequestBuilders.multipart( "/admin/vxfs") +//// .file(prodFile) +//// .param("vxf", resvxf) +//// .session( (MockHttpSession) session ) +//// ) +//// .andExpect(status().isOk()); +// +// assertThat( vxfService.getVxFsByCategory((long) -1) .size() ) +// .isEqualTo( 1 ); +// +// mvc.perform(get("/categories") +// .with( SecurityMockMvcRequestPostProcessors.csrf()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andExpect( jsonPath("$[0].name", is("None")) ) +// .andExpect( jsonPath("$[1].name", is("Networking"))) +// .andExpect( jsonPath("$[1].vxFscount", is( 1 ))); +// +// } + + +// @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) +// @Test +// public void deleteVxF() throws Exception { +// +// addVxF(); +// +// UserSession pu = new UserSession(); +// pu.setUsername("admin"); +// pu.setPassword("changeme"); +// +//// /** +//// * auth +//// */ +//// HttpSession session = mvc.perform(post("/sessions") +//// .with( SecurityMockMvcRequestPostProcessors.csrf()) +//// .contentType(MediaType.APPLICATION_JSON) +//// .content( toJson( pu ) )) +//// .andExpect(status().isOk()) +//// .andExpect(content() +//// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +//// .andExpect(jsonPath("username", is("admin"))) +//// .andReturn().getRequest().getSession(); +// +// assertThat( vxfService.getVxFsByCategory((long) -1) .size() ) +// .isEqualTo( 1 ); +// +// mvc.perform(get("/categories") +// .with( SecurityMockMvcRequestPostProcessors.csrf()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andExpect( jsonPath("$[0].name", is("None")) ) +// .andExpect( jsonPath("$[1].name", is("Networking"))) +// .andExpect( jsonPath("$[1].vxFscount", is( 1 ))) +// .andExpect( jsonPath("$[2].name", is("Service"))) +// .andExpect( jsonPath("$[2].vxFscount", is( 1 ))); +// +// String content = mvc.perform(get("/admin/vxfs") +// .contentType(MediaType.APPLICATION_JSON) +// .with( SecurityMockMvcRequestPostProcessors.csrf())) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andExpect(jsonPath("$[0].name", is( "cirros_vnfd" ))) +// .andReturn().getResponse().getContentAsString(); +// +// VxFMetadata[] v = toJsonObj( content, VxFMetadata[].class); +// +// mvc.perform(delete("/admin/vxfs/" + v[0].getId()) +// .with( SecurityMockMvcRequestPostProcessors.csrf())) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)); +// +// assertThat( vxfService.getVxFsByCategory((long) -1) .size() ) +// .isEqualTo( 1 ); +// +// } + + +// @WithMockUser(username="admin", roles = {"ADMIN","USER"}) +// @Test +// public void addNSD() throws Exception { +// +// UserSession pu = new UserSession(); +// pu.setUsername("osadmin"); +// pu.setPassword("changeme"); +// usersService.addPortalUserToUsersFromAuthServer("osadmin", "admin@admin.com", "First", "Last"); +// +//// /** +//// * auth +//// */ +//// HttpSession session = mvc.perform(post("/sessions") +//// .with( SecurityMockMvcRequestPostProcessors.csrf()) +//// .contentType(MediaType.APPLICATION_JSON) +//// .content( toJson( pu ) )) +//// .andExpect(status().isOk()) +//// .andExpect(content() +//// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +//// .andExpect(jsonPath("username", is("admin"))) +//// .andReturn().getRequest().getSession(); +// +// +// +// File vxfFile = new File( "src/test/resources/testvxf.txt" ); +// InputStream invxf = new FileInputStream( vxfFile ); +// String resvxf = IOUtils.toString( invxf, "UTF-8"); +// logger.info( "resvxf ========> " + resvxf ); +// +// File gzvxf = new File( "src/test/resources/cirros_vnf.tar.gz" ); +// InputStream inggzvxf = new FileInputStream( gzvxf ); +// MockMultipartFile prodFilevxf = new MockMultipartFile("prodFile", "cirros_vnf.tar.gz", "application/x-gzip", IOUtils.toByteArray( inggzvxf )); +// +//// Map sessionAttributes = new HashMap<>(); +//// Enumeration attr = session.getAttributeNames(); +//// while ( attr.hasMoreElements()) { +//// String aname = attr.nextElement(); +//// System.out.println("aname is: " + aname); +//// System.out.println("Value is: " + session.getAttribute(aname)); +//// sessionAttributes.put(aname, session.getAttribute(aname)); +//// } +// +// MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = +// (MockMultipartHttpServletRequestBuilder) multipart("/admin/vxfs") // .with( SecurityMockMvcRequestPostProcessors.csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content( toJson( pu ) )) -// .andExpect(status().isOk()) -// .andExpect(content() -// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("username", is("admin"))) -// .andReturn().getRequest().getSession(); - - - - - File vxfFile = new File( "src/test/resources/testvxf.txt" ); - InputStream in = new FileInputStream( vxfFile ); - String resvxf = IOUtils.toString(in, "UTF-8"); - logger.info( "resvxf ========> " + resvxf ); - - File gz = new File( "src/test/resources/cirros_vnf.tar.gz" ); - InputStream ing = new FileInputStream( gz ); - MockMultipartFile prodFile = new MockMultipartFile("prodFile", "cirros_vnf.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); - - -// Map sessionAttributes = new HashMap<>(); -// Enumeration attr = session.getAttributeNames(); -// while ( attr.hasMoreElements()) { -// String aname = attr.nextElement(); -// System.out.println("aname is: " + aname); -// System.out.println("Value is: " + session.getAttribute(aname)); -// sessionAttributes.put(aname, session.getAttribute(aname)); -// } - - - - - MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = - (MockMultipartHttpServletRequestBuilder) multipart("/admin/vxfs") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .with( SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN") ) ; - - mockMultipartHttpServletRequestBuilder.file( prodFile ); - mockMultipartHttpServletRequestBuilder.param("vxf", resvxf); - - mvc.perform(mockMultipartHttpServletRequestBuilder).andExpect(status().isOk()); - -// mvc.perform(MockMvcRequestBuilders.multipart( "/admin/vxfs") +// .with( SecurityMockMvcRequestPostProcessors.user("osadmin").roles("ADMIN") ) ; +// +// mockMultipartHttpServletRequestBuilder.file( prodFilevxf ); +// mockMultipartHttpServletRequestBuilder.param("vxf", resvxf); +// +// mvc.perform(mockMultipartHttpServletRequestBuilder).andExpect(status().isOk()); +// +// +// +// File nsdFile = new File( "src/test/resources/testnsd.txt" ); +// InputStream in = new FileInputStream( nsdFile ); +// String resnsd = IOUtils.toString(in, "UTF-8"); +// logger.info( "resnsd ========> " + resnsd ); +// +// File gz = new File( "src/test/resources/cirros_2vnf_ns.tar.gz" ); +// InputStream ing = new FileInputStream( gz ); +// MockMultipartFile prodFile = new MockMultipartFile("prodFile", "cirros_2vnf_ns.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); +// +// +// mvc.perform(MockMvcRequestBuilders.multipart("/admin/experiments") // .file(prodFile) -// .param("vxf", resvxf) -// .session( (MockHttpSession) session ) -// ) +// .param("exprm", resnsd)) // .andExpect(status().isOk()); - - assertThat( vxfService.getVxFsByCategory((long) -1) .size() ) - .isEqualTo( 1 ); - - mvc.perform(get("/categories") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect( jsonPath("$[0].name", is("None")) ) - .andExpect( jsonPath("$[1].name", is("Networking"))) - .andExpect( jsonPath("$[1].vxFscount", is( 1 ))); - - } - - - @WithMockUser(username="osadmin", roles = {"ADMIN","USER"}) - @Test - public void deleteVxF() throws Exception { - - addVxF(); - - UserSession pu = new UserSession(); - pu.setUsername("admin"); - pu.setPassword("changeme"); - -// /** -// * auth -// */ -// HttpSession session = mvc.perform(post("/sessions") +// +// assertThat( nsdService.getdNSDsByCategory((long) -1) .size() ) +// .isEqualTo( 1 ); +// +// ExperimentMetadata ansd = nsdService.getNSDByName( "cirros_2vnf_nsd" ); +// +// +// assertThat(ansd).isNotNull(); +// +// assertThat(ansd.getConstituentVxF().size()).isEqualTo(2); +// +// +// mvc.perform(get("/categories") // .with( SecurityMockMvcRequestPostProcessors.csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content( toJson( pu ) )) -// .andExpect(status().isOk()) -// .andExpect(content() -// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("username", is("admin"))) -// .andReturn().getRequest().getSession(); - - assertThat( vxfService.getVxFsByCategory((long) -1) .size() ) - .isEqualTo( 1 ); - - mvc.perform(get("/categories") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect( jsonPath("$[0].name", is("None")) ) - .andExpect( jsonPath("$[1].name", is("Networking"))) - .andExpect( jsonPath("$[1].vxFscount", is( 1 ))) - .andExpect( jsonPath("$[2].name", is("Service"))) - .andExpect( jsonPath("$[2].vxFscount", is( 1 ))); - - String content = mvc.perform(get("/admin/vxfs") - .contentType(MediaType.APPLICATION_JSON) - .with( SecurityMockMvcRequestPostProcessors.csrf())) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$[0].name", is( "cirros_vnfd" ))) - .andReturn().getResponse().getContentAsString(); - - VxFMetadata[] v = toJsonObj( content, VxFMetadata[].class); - - mvc.perform(delete("/admin/vxfs/" + v[0].getId()) - .with( SecurityMockMvcRequestPostProcessors.csrf())) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)); - - assertThat( vxfService.getVxFsByCategory((long) -1) .size() ) - .isEqualTo( 1 ); - - } - - - - @WithMockUser(username="admin", roles = {"ADMIN","USER"}) - @Test - public void addNSD() throws Exception { - - UserSession pu = new UserSession(); - pu.setUsername("admin"); - pu.setPassword("changeme"); - -// /** -// * auth -// */ -// HttpSession session = mvc.perform(post("/sessions") +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andExpect( jsonPath("$[0].name", is("None")) ) +// .andExpect( jsonPath("$[1].name", is("Networking"))) +// .andExpect( jsonPath("$[1].appscount", is( 1 ))); +// +// +// +// +// //https://patras5g.eu/apiportal/services/api/repo/admin/deployments/ +// +//// session = mvc.perform(post("/sessions") +//// .with( SecurityMockMvcRequestPostProcessors.csrf()) +//// .contentType(MediaType.APPLICATION_JSON) +//// .content( toJson( pu ) )) +//// .andExpect(status().isOk()) +//// .andExpect(content() +//// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +//// .andExpect(jsonPath("username", is("admin"))) +//// .andReturn().getRequest().getSession(); +// +// Infrastructure infr = new Infrastructure(); +// infr.setName( "Cloudville" ); +// +// mvc.perform(post("/admin/infrastructures") +// .with( SecurityMockMvcRequestPostProcessors.csrf()) +// .contentType(MediaType.APPLICATION_JSON) +// .content( toJson( infr ) ) +// ) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)); +// +// +// gz = new File( "src/test/resources/deploymentReq.txt" ); +// ing = new FileInputStream( gz ); +// resnsd = IOUtils.toString( ing, "UTF-8"); +// DeploymentDescriptor ddesc = toJsonObj( resnsd, DeploymentDescriptor.class ); +// +// String strddescResponse = mvc.perform(post("/admin/deployments") // .with( SecurityMockMvcRequestPostProcessors.csrf()) // .contentType(MediaType.APPLICATION_JSON) -// .content( toJson( pu ) )) -// .andExpect(status().isOk()) -// .andExpect(content() -// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("username", is("admin"))) -// .andReturn().getRequest().getSession(); - - - - File vxfFile = new File( "src/test/resources/testvxf.txt" ); - InputStream invxf = new FileInputStream( vxfFile ); - String resvxf = IOUtils.toString( invxf, "UTF-8"); - logger.info( "resvxf ========> " + resvxf ); - - File gzvxf = new File( "src/test/resources/cirros_vnf.tar.gz" ); - InputStream inggzvxf = new FileInputStream( gzvxf ); - MockMultipartFile prodFilevxf = new MockMultipartFile("prodFile", "cirros_vnf.tar.gz", "application/x-gzip", IOUtils.toByteArray( inggzvxf )); - -// Map sessionAttributes = new HashMap<>(); -// Enumeration attr = session.getAttributeNames(); -// while ( attr.hasMoreElements()) { -// String aname = attr.nextElement(); -// System.out.println("aname is: " + aname); -// System.out.println("Value is: " + session.getAttribute(aname)); -// sessionAttributes.put(aname, session.getAttribute(aname)); -// } - - MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = - (MockMultipartHttpServletRequestBuilder) multipart("/admin/vxfs") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .with( SecurityMockMvcRequestPostProcessors.user("osadmin").roles("ADMIN") ) ; - - mockMultipartHttpServletRequestBuilder.file( prodFilevxf ); - mockMultipartHttpServletRequestBuilder.param("vxf", resvxf); - - mvc.perform(mockMultipartHttpServletRequestBuilder).andExpect(status().isOk()); - - - - File nsdFile = new File( "src/test/resources/testnsd.txt" ); - InputStream in = new FileInputStream( nsdFile ); - String resnsd = IOUtils.toString(in, "UTF-8"); - logger.info( "resnsd ========> " + resnsd ); - - File gz = new File( "src/test/resources/cirros_2vnf_ns.tar.gz" ); - InputStream ing = new FileInputStream( gz ); - MockMultipartFile prodFile = new MockMultipartFile("prodFile", "cirros_2vnf_ns.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); - - - mvc.perform(MockMvcRequestBuilders.multipart("/admin/experiments") - .file(prodFile) - .param("exprm", resnsd)) - .andExpect(status().isOk()); - - assertThat( nsdService.getdNSDsByCategory((long) -1) .size() ) - .isEqualTo( 1 ); - - ExperimentMetadata ansd = nsdService.getNSDByName( "cirros_2vnf_nsd" ); - - - assertThat(ansd).isNotNull(); - - assertThat(ansd.getConstituentVxF().size()).isEqualTo(2); - - - mvc.perform(get("/categories") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect( jsonPath("$[0].name", is("None")) ) - .andExpect( jsonPath("$[1].name", is("Networking"))) - .andExpect( jsonPath("$[1].appscount", is( 1 ))); - - - - - //https://patras5g.eu/apiportal/services/api/repo/admin/deployments/ - -// session = mvc.perform(post("/sessions") -// .with( SecurityMockMvcRequestPostProcessors.csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content( toJson( pu ) )) -// .andExpect(status().isOk()) -// .andExpect(content() -// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("username", is("admin"))) -// .andReturn().getRequest().getSession(); - - Infrastructure infr = new Infrastructure(); - infr.setName( "Cloudville" ); - - mvc.perform(post("/admin/infrastructures") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .content( toJson( infr ) ) - ) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)); - - - gz = new File( "src/test/resources/deploymentReq.txt" ); - ing = new FileInputStream( gz ); - resnsd = IOUtils.toString( ing, "UTF-8"); - DeploymentDescriptor ddesc = toJsonObj( resnsd, DeploymentDescriptor.class ); - - String strddescResponse = mvc.perform(post("/admin/deployments") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON) - .content( toJson( ddesc ) ) - ) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andReturn().getResponse().getContentAsString(); - - - logger.info( "strddescResponse ========> " + strddescResponse ); - DeploymentDescriptor ddescResponse = toJsonObj( strddescResponse, DeploymentDescriptor.class); - - assertThat(ddescResponse).isNotNull(); - assertThat(ddescResponse.getVxfPlacements().size()).isEqualTo(2); - assertThat(ddescResponse.getVxfPlacements().get(0).getConstituentVxF() ).isNotNull(); - assertThat(ddescResponse.getVxfPlacements().get(0).getInfrastructure() ).isNotNull(); - assertThat(ddescResponse.getVxfPlacements().get(1).getConstituentVxF() ).isNotNull(); - assertThat(ddescResponse.getVxfPlacements().get(1).getInfrastructure() ).isNotNull(); - - } - - - @WithMockUser(username="admin", roles = {"ADMIN","USER"}) - @Test - public void deleteNSD() throws Exception { - - - UserSession pu = new UserSession(); - pu.setUsername("admin"); - pu.setPassword("changeme"); - -// /** -// * auth -// */ -// HttpSession session = mvc.perform(post("/sessions") -// .with( SecurityMockMvcRequestPostProcessors.csrf()) -// .contentType(MediaType.APPLICATION_JSON) -// .content( toJson( pu ) )) -// .andExpect(status().isOk()) -// .andExpect(content() -// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) -// .andExpect(jsonPath("username", is("admin"))) -// .andReturn().getRequest().getSession(); - - File nsdFile = new File( "src/test/resources/testnsd.txt" ); - InputStream in = new FileInputStream( nsdFile ); - String resnsd = IOUtils.toString(in, "UTF-8"); - logger.info( "resnsd ========> " + resnsd ); - - File gz = new File( "src/test/resources/cirros_2vnf_ns.tar.gz" ); - InputStream ing = new FileInputStream( gz ); - MockMultipartFile prodFile = new MockMultipartFile("prodFile", "cirros_2vnf_ns.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); - - - mvc.perform(MockMvcRequestBuilders.multipart("/admin/experiments") - .file(prodFile) - .param("exprm", resnsd) - .with( SecurityMockMvcRequestPostProcessors.csrf())) - .andExpect(status().isOk()); - - assertThat( nsdService.getdNSDsByCategory((long) -1) .size() ) - .isEqualTo( 1 ); - - mvc.perform(get("/categories") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect( jsonPath("$[0].name", is("None")) ) - .andExpect( jsonPath("$[1].name", is("Networking"))) - .andExpect( jsonPath("$[1].appscount", is( 1 ))) - .andExpect( jsonPath("$[2].name", is("Service"))) - .andExpect( jsonPath("$[2].appscount", is( 1 ))); - - String content = mvc.perform(get("/admin/experiments") - .with( SecurityMockMvcRequestPostProcessors.csrf()) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$[0].name", is( "cirros_2vnf_nsd" ))) - .andReturn().getResponse().getContentAsString(); - - - ExperimentMetadata[] n = toJsonObj( content, ExperimentMetadata[].class ); - - mvc.perform(delete("/admin/experiments/" + n[0].getId() ) - .with( SecurityMockMvcRequestPostProcessors.csrf())) - .andExpect(status().isOk()) - .andExpect(content() - .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - ; - - assertThat( nsdService.getdNSDsByCategory((long) -1) .size() ) - .isEqualTo( 0 ); +// .content( toJson( ddesc ) ) +// ) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andReturn().getResponse().getContentAsString(); +// +// +// logger.info( "strddescResponse ========> " + strddescResponse ); +// DeploymentDescriptor ddescResponse = toJsonObj( strddescResponse, DeploymentDescriptor.class); +// +// assertThat(ddescResponse).isNotNull(); +// assertThat(ddescResponse.getVxfPlacements().size()).isEqualTo(2); +// assertThat(ddescResponse.getVxfPlacements().get(0).getConstituentVxF() ).isNotNull(); +// assertThat(ddescResponse.getVxfPlacements().get(0).getInfrastructure() ).isNotNull(); +// assertThat(ddescResponse.getVxfPlacements().get(1).getConstituentVxF() ).isNotNull(); +// assertThat(ddescResponse.getVxfPlacements().get(1).getInfrastructure() ).isNotNull(); +// +// } + + +// @WithMockUser(username="admin", roles = {"ADMIN","USER"}) +// @Test +// public void deleteNSD() throws Exception { +// +// +// UserSession pu = new UserSession(); +// pu.setUsername("admin"); +// pu.setPassword("changeme"); +// +//// /** +//// * auth +//// */ +//// HttpSession session = mvc.perform(post("/sessions") +//// .with( SecurityMockMvcRequestPostProcessors.csrf()) +//// .contentType(MediaType.APPLICATION_JSON) +//// .content( toJson( pu ) )) +//// .andExpect(status().isOk()) +//// .andExpect(content() +//// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +//// .andExpect(jsonPath("username", is("admin"))) +//// .andReturn().getRequest().getSession(); +// +// File nsdFile = new File( "src/test/resources/testnsd.txt" ); +// InputStream in = new FileInputStream( nsdFile ); +// String resnsd = IOUtils.toString(in, "UTF-8"); +// logger.info( "resnsd ========> " + resnsd ); +// +// File gz = new File( "src/test/resources/cirros_2vnf_ns.tar.gz" ); +// InputStream ing = new FileInputStream( gz ); +// MockMultipartFile prodFile = new MockMultipartFile("prodFile", "cirros_2vnf_ns.tar.gz", "application/x-gzip", IOUtils.toByteArray(ing)); +// +// +// mvc.perform(MockMvcRequestBuilders.multipart("/admin/experiments") +// .file(prodFile) +// .param("exprm", resnsd) +// .with( SecurityMockMvcRequestPostProcessors.csrf())) +// .andExpect(status().isOk()); +// +// assertThat( nsdService.getdNSDsByCategory((long) -1) .size() ) +// .isEqualTo( 1 ); +// +// mvc.perform(get("/categories") +// .with( SecurityMockMvcRequestPostProcessors.csrf()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andExpect( jsonPath("$[0].name", is("None")) ) +// .andExpect( jsonPath("$[1].name", is("Networking"))) +// .andExpect( jsonPath("$[1].appscount", is( 1 ))) +// .andExpect( jsonPath("$[2].name", is("Service"))) +// .andExpect( jsonPath("$[2].appscount", is( 1 ))); +// +// String content = mvc.perform(get("/admin/experiments") +// .with( SecurityMockMvcRequestPostProcessors.csrf()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// .andExpect(jsonPath("$[0].name", is( "cirros_2vnf_nsd" ))) +// .andReturn().getResponse().getContentAsString(); +// +// +// ExperimentMetadata[] n = toJsonObj( content, ExperimentMetadata[].class ); +// +// mvc.perform(delete("/admin/experiments/" + n[0].getId() ) +// .with( SecurityMockMvcRequestPostProcessors.csrf())) +// .andExpect(status().isOk()) +// .andExpect(content() +// .contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) +// ; +// +// assertThat( nsdService.getdNSDsByCategory((long) -1) .size() ) +// .isEqualTo( 0 ); +// +// } - } }