List of usage examples for org.springframework.http MediaType MULTIPART_FORM_DATA
MediaType MULTIPART_FORM_DATA
To view the source code for org.springframework.http MediaType MULTIPART_FORM_DATA.
Click Source Link
From source file:fr.treeptik.cloudunit.modules.redis.SpringBootRedisModuleControllerTestIT.java
@Test public void test20_CreateServerThenAddModuleThenDeployApplicationThenRemoveModule() throws Exception { logger.info("Create an application, add a " + module + " module and delete it"); String binary = "spring-boot-redis-1.0.0.jar"; // create an application server String jsonString = "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + server + "\"}"; ResultActions resultats = mockMvc.perform( post("/application").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); // verify if app exists resultats = mockMvc.perform(/*w w w . j av a2 s . com*/ get("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(jsonPath("name").value(applicationName.toLowerCase())); // add a module jsonString = "{\"applicationName\":\"" + applicationName + "\", \"imageName\":\"" + module + "\"}"; resultats = mockMvc.perform( post("/module").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); // Change to Java 8 for compliance with example fatjar jsonString = "{\"applicationName\":\"" + applicationName + "\",\"jvmMemory\":\"512\",\"jvmOptions\":\"-Dkey1=value1\",\"jvmRelease\":\"jdk1.8.0_25\"}"; resultats = mockMvc.perform(put("/server/configuration/jvm").session(session) .contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); // Open the 8080 port for fatjar jsonString = "{\"applicationName\":\"" + applicationName + "\",\"portToOpen\":\"8080\",\"portNature\":\"web\"}"; resultats = this.mockMvc.perform(post("/application/ports").session(session) .contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()).andDo(print()); // Expected values String genericModule = cuInstanceName.toLowerCase() + "-johndoe-" + applicationName.toLowerCase() + "-" + module + "-1"; String gitModule = cuInstanceName.toLowerCase() + "-johndoe-" + applicationName.toLowerCase() + "-git-1"; String managerExpected = "http://" + managerPrefix + "1-" + applicationName.toLowerCase() + "-johndoe-admin.cloudunit.dev/" + managerSuffix; // get the detail of the applications to verify modules addition resultats = mockMvc.perform( get("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON)) .andDo(print()); System.out.println(resultats.andReturn().getResponse().getContentAsString()); resultats.andExpect(status().isOk()).andExpect(jsonPath("$.modules[0].name").value(gitModule)) .andExpect(jsonPath("$.modules[0].status").value("START")) .andExpect(jsonPath("$.modules[1].status").value("START")) .andExpect(jsonPath("$.modules[1].name").value(genericModule)) .andExpect(jsonPath("$.modules[1].managerLocation").value(managerExpected)); String fullContent = resultats.andReturn().getResponse().getContentAsString(); String userNameRedis = JsonPath.read(fullContent, "$.modules[1].moduleInfos.username"); String passwordRedis = JsonPath.read(fullContent, "$.modules[1].moduleInfos.password"); // Deploy the fat Jar resultats = mockMvc.perform(MockMvcRequestBuilders.fileUpload("/application/" + applicationName + "/deploy") .file(downloadAndPrepareFileToDeploy(binary, "https://github.com/Treeptik/CloudUnit/releases/download/1.0/" + binary)) .session(session).contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); resultats.andExpect(status().is2xxSuccessful()); String urlToCall = "http://" + applicationName.toLowerCase() + "-johndoe-forward-8080.cloudunit.dev"; logger.debug(urlToCall); int i = 0; String content = null; // Wait for the deployment while (i++ < TestUtils.NB_ITERATION_MAX) { content = getUrlContentPage(urlToCall); Thread.sleep(1000); if (content == null || content.contains("Redis is great")) { break; } } logger.debug(content); if (content != null) { Assert.assertTrue(content.contains("Redis is great")); } logger.info("Delete application : " + applicationName); resultats = mockMvc.perform( delete("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(status().isOk()); }
From source file:fr.treeptik.cloudunit.snapshot.AbstractSnapshotControllerTestIT.java
@Test public void test021_CloneAHelloworldApplicationSnapshot() throws Exception { logger.info("**************************************"); logger.info("Create Tomcat server"); logger.info("**************************************"); String jsonString = "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + release + "\"}"; ResultActions resultats = mockMvc.perform( post("/application").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Deploy a helloworld Application"); logger.info("**************************************"); resultats = mockMvc.perform(fileUpload("/application/" + applicationName + "/deploy") .file(downloadAndPrepareFileToDeploy("helloworld.war", "https://github.com/Treeptik/CloudUnit/releases/download/1.0/helloworld.war")) .session(session).contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); resultats.andExpect(status().is2xxSuccessful()); String urlToCall = "http://" + applicationName.toLowerCase() + "-johndoe-admin.cloudunit.dev"; String contentPage = getUrlContentPage(urlToCall); if (release.contains("jboss")) { int counter = 0; while (contentPage.contains("Welcome to WildFly") && counter++ < 10) { contentPage = getUrlContentPage(urlToCall); Thread.sleep(1000);/*w ww.ja v a 2 s.c o m*/ } } Assert.assertTrue(contentPage.contains("CloudUnit PaaS")); logger.info("**************************************"); logger.info("Create a snapshot"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "\", \"tag\":\"" + tagName + "\", \"description\":\"This is a test snapshot\"}"; logger.info(jsonString); resultats = mockMvc.perform( post("/snapshot").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)) .andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("List the snapshot"); logger.info("**************************************"); resultats = mockMvc.perform(get("/snapshot/list").session(session)).andDo(print()); resultats.andExpect(status().isOk()).andExpect(jsonPath("$[0].tag").value(tagName.toLowerCase())); logger.info("**************************************"); logger.info("Delete the original application : " + applicationName); logger.info("**************************************"); resultats = mockMvc.perform( delete("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Clone an application : " + applicationName + "cloned"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "cloned" + "\", \"tag\":\"" + tagName + "\", \"description\":\"This is a test snapshot\"}"; resultats = mockMvc.perform(post("/snapshot/clone").session(session).contentType(MediaType.APPLICATION_JSON) .content(jsonString)).andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Start the application : " + applicationName + "cloned"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "cloned" + "\"}"; resultats = this.mockMvc.perform(post("/application/start").session(session) .contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Check the keyword of " + applicationName + "cloned"); logger.info("**************************************"); urlToCall = "http://" + applicationName.toLowerCase() + "cloned" + "-johndoe-admin.cloudunit.dev"; contentPage = getUrlContentPage(urlToCall); if (release.contains("jboss")) { int counter = 0; while (contentPage.contains("Welcome to WildFly") && counter++ < 10) { contentPage = getUrlContentPage(urlToCall); Thread.sleep(1000); } } Assert.assertTrue(contentPage.contains("CloudUnit PaaS")); logger.info("**************************************"); logger.info("Delete the snapshot"); logger.info("**************************************"); resultats = mockMvc.perform(delete("/snapshot/" + tagName).session(session)).andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Delete the cloned application"); logger.info("**************************************"); resultats = mockMvc.perform(delete("/application/" + applicationName + "cloned").session(session) .contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(status().isOk()); }
From source file:cn.org.once.cstack.modules.AbstractModuleControllerTestIT.java
@Test public void test_runScript() throws Exception { requestAddModule();/*from ww w .j a v a2 s.c o m*/ String filename = FilenameUtils.getName(testScriptPath); if (filename == null) { logger.info("No script found - test escape"); } else { MockMultipartFile file = new MockMultipartFile("file", filename, "application/sql", new FileInputStream(testScriptPath)); String genericModule = NamingUtils.getContainerName(applicationName, module, "johndoe"); ResultActions result = mockMvc.perform(fileUpload("/module/{moduleName}/run-script", genericModule) .file(file).session(session).contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); result.andExpect(status().isOk()); } }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java
private String submitJob(final int documentationId, final JobRequest jobRequest, final List<MockMultipartFile> attachments) throws Exception { final MvcResult result; if (attachments != null) { final RestDocumentationResultHandler createResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/submitJobWithAttachments/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.MULTIPART_FORM_DATA_VALUE)), // Request headers RequestDocumentation.requestParts( RequestDocumentation.partWithName("request").description( "The job request JSON. Content type must be application/json for part"), RequestDocumentation.partWithName("attachment").description( "An attachment file. There can be multiple. Type should be octet-stream")), // Request parts Snippets.LOCATION_HEADER // Response Headers );/* w ww . j a v a 2 s. co m*/ final MockMultipartFile json = new MockMultipartFile("request", "", MediaType.APPLICATION_JSON_VALUE, this.objectMapper.writeValueAsBytes(jobRequest)); final MockMultipartHttpServletRequestBuilder builder = RestDocumentationRequestBuilders .fileUpload(JOBS_API).file(json); for (final MockMultipartFile attachment : attachments) { builder.file(attachment); } builder.contentType(MediaType.MULTIPART_FORM_DATA); result = this.mvc.perform(builder).andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) .andDo(createResultHandler).andReturn(); } else { // Use regular POST final RestDocumentationResultHandler createResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/submitJobWithoutAttachments/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request headers Snippets.getJobRequestRequestPayload(), // Request Fields Snippets.LOCATION_HEADER // Response Headers ); result = this.mvc .perform(MockMvcRequestBuilders.post(JOBS_API).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(jobRequest))) .andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) .andDo(createResultHandler).andReturn(); } return this.getIdFromLocation(result.getResponse().getHeader(HttpHeaders.LOCATION)); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientV1.java
private HttpEntity<MultiValueMap<String, ?>> generatePartialResourceRequest( UploadApplicationPayload application, CloudResources knownRemoteResources) throws IOException { MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>(2); if (application.getNumEntries() > 0) { //If the entire app contents are cached, send nothing body.add("application", application); }//from w w w. jav a 2 s. co m ObjectMapper mapper = new ObjectMapper(); String knownRemoteResourcesPayload = mapper.writeValueAsString(knownRemoteResources); body.add("resources", knownRemoteResourcesPayload); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); return new HttpEntity<MultiValueMap<String, ?>>(body, headers); }
From source file:fr.treeptik.cloudunit.snapshot.AbstractSnapshotControllerTestIT.java
private void cloneASnapshotWithApplicationWithModuleAndADeployment(String module, String appName, String keywordIntoPage) throws Exception { logger.info("**************************************"); logger.info("Create app server"); logger.info("**************************************"); String jsonString = "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + release + "\"}"; ResultActions resultats = mockMvc.perform( post("/application").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Add the module"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "\", \"imageName\":\"" + module + "\"}"; resultats = mockMvc.perform(/*from w w w. j av a 2 s .com*/ post("/module").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)) .andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Deploy a helloworld Application"); logger.info("**************************************"); logger.info("Deploy an " + module + " based application"); resultats = mockMvc.perform(MockMvcRequestBuilders.fileUpload("/application/" + applicationName + "/deploy") .file(downloadAndPrepareFileToDeploy(appName + ".war", "https://github.com/Treeptik/CloudUnit/releases/download/1.0/" + appName + ".war")) .session(session).contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); // test the application content page resultats.andExpect(status().is2xxSuccessful()); String urlToCall = "http://" + applicationName.toLowerCase() + "-johndoe-admin.cloudunit.dev"; String contentPage = getUrlContentPage(urlToCall); if (release.contains("jboss")) { int counter = 0; while (contentPage.contains("Welcome to WildFly") && counter++ < 10) { contentPage = getUrlContentPage(urlToCall); Thread.sleep(1000); } } Assert.assertTrue(contentPage.contains(keywordIntoPage)); logger.info("**************************************"); logger.info("Create a snapshot"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "\", \"tag\":\"" + tagName + "\", \"description\":\"This is a test snapshot\"}"; logger.info(jsonString); resultats = mockMvc.perform( post("/snapshot").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)) .andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("List the snapshot"); logger.info("**************************************"); resultats = mockMvc.perform(get("/snapshot/list").session(session)).andDo(print()); resultats.andExpect(status().isOk()).andExpect(jsonPath("$[0].tag").value(tagName.toLowerCase())); logger.info("**************************************"); logger.info("Delete the original application : " + applicationName); logger.info("**************************************"); resultats = mockMvc.perform( delete("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Clone an application : " + applicationName + "cloned"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "cloned" + "\", \"tag\":\"" + tagName + "\", \"description\":\"This is a test snapshot\"}"; resultats = mockMvc.perform(post("/snapshot/clone").session(session).contentType(MediaType.APPLICATION_JSON) .content(jsonString)).andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Start the application : " + applicationName + "cloned"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "cloned" + "\"}"; resultats = this.mockMvc.perform(post("/application/start").session(session) .contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Check the contentPage of " + applicationName + "cloned"); logger.info("**************************************"); urlToCall = "http://" + applicationName.toLowerCase() + "cloned" + "-johndoe-admin.cloudunit.dev"; if (release.contains("jboss")) { int counter = 0; contentPage = getUrlContentPage(urlToCall); while (contentPage.contains("Welcome to WildFly") && counter++ < 10) { contentPage = getUrlContentPage(urlToCall); Thread.sleep(1000); } } Assert.assertTrue(contentPage.contains(keywordIntoPage)); logger.info("**************************************"); logger.info("Delete the snapshot"); logger.info("**************************************"); resultats = mockMvc.perform(delete("/snapshot/" + tagName).session(session)).andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Delete the cloned application"); logger.info("**************************************"); resultats = mockMvc.perform(delete("/application/" + applicationName + "cloned").session(session) .contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(status().isOk()); }
From source file:fr.treeptik.cloudunit.snapshot.AbstractSnapshotControllerTestIT.java
private void createApplicationSnapshotWithAModuleAndADeployment(String module, String appName, String keywordIntoPage) throws Exception { logger.info("**************************************"); logger.info("Create Tomcat server"); logger.info("**************************************"); String jsonString = "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + release + "\"}"; ResultActions resultats = mockMvc.perform( post("/application").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Add the module"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "\", \"imageName\":\"" + module + "\"}"; resultats = mockMvc.perform(//from www . ja v a 2 s .c o m post("/module").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)) .andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Deploy a helloworld Application"); logger.info("**************************************"); logger.info("Deploy an " + module + " based application"); resultats = mockMvc.perform(MockMvcRequestBuilders.fileUpload("/application/" + applicationName + "/deploy") .file(downloadAndPrepareFileToDeploy(appName + ".war", "https://github.com/Treeptik/CloudUnit/releases/download/1.0/" + appName + ".war")) .session(session).contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); // test the application content page resultats.andExpect(status().is2xxSuccessful()); String urlToCall = "http://" + applicationName.toLowerCase() + "-johndoe-admin.cloudunit.dev"; String contentPage = getUrlContentPage(urlToCall); if (release.contains("jboss")) { int counter = 0; while (contentPage.contains("Welcome to WildFly") && counter++ < 10) { contentPage = getUrlContentPage(urlToCall); Thread.sleep(1000); } } Assert.assertTrue(contentPage.contains(keywordIntoPage)); logger.info("**************************************"); logger.info("Create a snapshot"); logger.info("**************************************"); jsonString = "{\"applicationName\":\"" + applicationName + "\", \"tag\":\"" + tagName + "\", \"description\":\"This is a test snapshot\"}"; logger.info(jsonString); resultats = mockMvc.perform( post("/snapshot").session(session).contentType(MediaType.APPLICATION_JSON).content(jsonString)) .andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("List the snapshot"); logger.info("**************************************"); resultats = mockMvc.perform(get("/snapshot/list").session(session)).andDo(print()); resultats.andExpect(status().isOk()).andExpect(jsonPath("$[0].tag").value(tagName.toLowerCase())); logger.info("**************************************"); logger.info("Delete the snapshot"); logger.info("**************************************"); resultats = mockMvc.perform(delete("/snapshot/" + tagName).session(session)).andDo(print()); resultats.andExpect(status().isOk()); logger.info("**************************************"); logger.info("Delete application : " + applicationName); logger.info("**************************************"); resultats = mockMvc.perform( delete("/application/" + applicationName).session(session).contentType(MediaType.APPLICATION_JSON)); resultats.andExpect(status().isOk()); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientImpl.java
private HttpEntity<MultiValueMap<String, ?>> generatePartialResourceRequest( UploadApplicationPayload application, CloudResources knownRemoteResources) throws IOException { MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>(2); body.add("application", application); ObjectMapper mapper = new ObjectMapper(); String knownRemoteResourcesPayload = mapper.writeValueAsString(knownRemoteResources); body.add("resources", knownRemoteResourcesPayload); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); return new HttpEntity<MultiValueMap<String, ?>>(body, headers); }
From source file:fr.treeptik.cloudunit.explorer.FileControllerTestIT.java
private ResultActions upload(File localFile, String remotePath) throws Exception { String container = "int-johndoe-" + applicationName + "-tomcat-8"; String url = "/file/container/" + container + "/application/" + applicationName + "?path=" + remotePath; MockMultipartFile mockMultipartFile = new MockMultipartFile("file", localFile.getName(), "multipart/form-data", new FileInputStream(localFile)); return mockMvc.perform(MockMvcRequestBuilders.fileUpload(url).file(mockMultipartFile).session(session) .contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); }
From source file:fr.treeptik.cloudunit.modules.AbstractModuleControllerTestIT.java
@Test public void test_runScript() throws Exception { requestAddModule();// ww w . jav a 2s . com String filename = FilenameUtils.getName(testScriptPath); if (filename == null) { logger.info("No script found - test escape"); } else { MockMultipartFile file = new MockMultipartFile("file", filename, "application/sql", new FileInputStream(testScriptPath)); String genericModule = cuInstanceName.toLowerCase() + "-johndoe-" + applicationName.toLowerCase() + "-" + module; ResultActions result = mockMvc.perform(fileUpload("/module/{moduleName}/run-script", genericModule) .file(file).session(session).contentType(MediaType.MULTIPART_FORM_DATA)).andDo(print()); result.andExpect(status().isOk()); } }