From 1a31e5ee9953a4740ddd89ffc41bfa261bcff1f0 Mon Sep 17 00:00:00 2001 From: Mariela Michalek Date: Sun, 9 Feb 2014 18:37:10 -0300 Subject: [PATCH] Refactor Imports and Helper --- .../test/rest/RestAccountITCase.java | 8 ----- .../test/rest/RestAdminITCase.java | 30 +++++-------------- .../com/wisemapping/test/rest/RestHelper.java | 8 ++--- .../test/rest/RestMindmapITCase.java | 5 ---- .../test/rest/RestMindmapLabelITCase.java | 17 ++--------- 5 files changed, 13 insertions(+), 55 deletions(-) diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountITCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountITCase.java index 6676f5b2..114dea9c 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountITCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAccountITCase.java @@ -20,24 +20,16 @@ package com.wisemapping.test.rest; import com.wisemapping.rest.model.RestUser; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.security.crypto.codec.Base64; import org.springframework.web.client.RestTemplate; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import java.io.IOException; -import java.net.HttpURLConnection; import java.net.URI; -import java.util.ArrayList; -import java.util.List; import static com.wisemapping.test.rest.RestHelper.ADMIN_CREDENTIALS; import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAdminITCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAdminITCase.java index d4c420e7..7204d500 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAdminITCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestAdminITCase.java @@ -20,29 +20,25 @@ package com.wisemapping.test.rest; import com.wisemapping.rest.model.RestUser; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.springframework.http.*; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.security.crypto.codec.Base64; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.net.URI; + import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; import static com.wisemapping.test.rest.RestHelper.HOST_PORT; +import static com.wisemapping.test.rest.RestHelper.createHeaders; import static com.wisemapping.test.rest.RestHelper.createTemplate; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - - @Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function") public class RestAdminITCase { @@ -141,16 +137,6 @@ public class RestAdminITCase { return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity); } - private HttpHeaders createHeaders(@NotNull MediaType mediaType) { - List acceptableMediaTypes = new ArrayList(); - acceptableMediaTypes.add(mediaType); - - final HttpHeaders result = new HttpHeaders(); - result.setAccept(acceptableMediaTypes); - result.setContentType(mediaType); - return result; - } - private RestUser createDummyUser() { final RestUser restUser = new RestUser(); final String username = "foo-to-delete" + System.nanoTime(); diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java index 69b3ceb3..a9ed4ee4 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestHelper.java @@ -1,7 +1,5 @@ package com.wisemapping.test.rest; -import com.wisemapping.rest.model.RestUser; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -21,7 +19,7 @@ public class RestHelper { public static final String BASE_REST_URL = HOST_PORT + "/service"; public static final String ADMIN_CREDENTIALS = "admin@wisemapping.org" + ":" + "admin"; - public static HttpHeaders createHeaders(@NotNull MediaType mediaType) { + static HttpHeaders createHeaders(@NotNull MediaType mediaType) { List acceptableMediaTypes = new ArrayList(); acceptableMediaTypes.add(mediaType); @@ -31,7 +29,7 @@ public class RestHelper { return result; } - public static RestTemplate createTemplate(@NotNull final String authorisation) { + static RestTemplate createTemplate(@NotNull final String authorisation) { SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory() { @Override protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException { @@ -46,7 +44,7 @@ public class RestHelper { } @DataProvider(name = "ContentType-Provider-Function") - public static Object[][] contentTypes() { + static Object[][] contentTypes() { return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}}; } diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java index de5e8944..83c962db 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapITCase.java @@ -13,19 +13,14 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.security.crypto.codec.Base64; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.testng.SkipException; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.IOException; -import java.net.HttpURLConnection; import java.net.URI; -import java.util.ArrayList; import java.util.List; import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapLabelITCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapLabelITCase.java index e0ab59c7..1bfe46d6 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapLabelITCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapLabelITCase.java @@ -3,11 +3,7 @@ package com.wisemapping.test.rest; import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.rest.model.RestLabel; -import com.wisemapping.rest.model.RestMindmap; -import com.wisemapping.rest.model.RestMindmapInfo; -import com.wisemapping.rest.model.RestMindmapList; import com.wisemapping.rest.model.RestLabelList; -import com.wisemapping.rest.model.RestUser; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.http.HttpEntity; @@ -15,25 +11,16 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.security.crypto.codec.Base64; -import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; -import org.testng.SkipException; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.IOException; -import java.net.HttpURLConnection; import java.net.URI; -import java.util.ArrayList; import java.util.List; import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; -import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; @Test public class RestMindmapLabelITCase { @@ -82,7 +69,7 @@ public class RestMindmapLabelITCase { } - private URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException, WiseMappingException { + static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException, WiseMappingException { final RestLabel restLabel = new RestLabel(); restLabel.setTitle(title); restLabel.setColor("#666666"); @@ -92,7 +79,7 @@ public class RestMindmapLabelITCase { return template.postForLocation(BASE_REST_URL + "/labels", createUserEntity); } - private URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException, WiseMappingException { + static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException, WiseMappingException { return addNewLabel(requestHeaders, template, title, null); } } \ No newline at end of file