Refactor Imports and Helper

This commit is contained in:
Mariela Michalek 2014-02-09 18:37:10 -03:00
parent d48abe6121
commit 1a31e5ee99
5 changed files with 13 additions and 55 deletions

View File

@ -20,24 +20,16 @@ package com.wisemapping.test.rest;
import com.wisemapping.rest.model.RestUser; import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.springframework.web.client.RestTemplate;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI; 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.ADMIN_CREDENTIALS;
import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL;

View File

@ -20,29 +20,25 @@ package com.wisemapping.test.rest;
import com.wisemapping.rest.model.RestUser; import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.http.*; import org.springframework.http.HttpEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.HttpHeaders;
import org.springframework.security.crypto.codec.Base64; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; 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.BASE_REST_URL;
import static com.wisemapping.test.rest.RestHelper.HOST_PORT; 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 com.wisemapping.test.rest.RestHelper.createTemplate;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail; 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") @Test(dataProviderClass = RestHelper.class, dataProvider="ContentType-Provider-Function")
public class RestAdminITCase { public class RestAdminITCase {
@ -141,16 +137,6 @@ public class RestAdminITCase {
return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity); return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity);
} }
private HttpHeaders createHeaders(@NotNull MediaType mediaType) {
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(mediaType);
final HttpHeaders result = new HttpHeaders();
result.setAccept(acceptableMediaTypes);
result.setContentType(mediaType);
return result;
}
private RestUser createDummyUser() { private RestUser createDummyUser() {
final RestUser restUser = new RestUser(); final RestUser restUser = new RestUser();
final String username = "foo-to-delete" + System.nanoTime(); final String username = "foo-to-delete" + System.nanoTime();

View File

@ -1,7 +1,5 @@
package com.wisemapping.test.rest; package com.wisemapping.test.rest;
import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; 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 BASE_REST_URL = HOST_PORT + "/service";
public static final String ADMIN_CREDENTIALS = "admin@wisemapping.org" + ":" + "admin"; public static final String ADMIN_CREDENTIALS = "admin@wisemapping.org" + ":" + "admin";
public static HttpHeaders createHeaders(@NotNull MediaType mediaType) { static HttpHeaders createHeaders(@NotNull MediaType mediaType) {
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(mediaType); acceptableMediaTypes.add(mediaType);
@ -31,7 +29,7 @@ public class RestHelper {
return result; return result;
} }
public static RestTemplate createTemplate(@NotNull final String authorisation) { static RestTemplate createTemplate(@NotNull final String authorisation) {
SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory() { SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory() {
@Override @Override
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException { protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
@ -46,7 +44,7 @@ public class RestHelper {
} }
@DataProvider(name = "ContentType-Provider-Function") @DataProvider(name = "ContentType-Provider-Function")
public static Object[][] contentTypes() { static Object[][] contentTypes() {
return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}}; return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}};
} }

View File

@ -13,19 +13,14 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.HttpClientErrorException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.testng.SkipException; import org.testng.SkipException;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL;

View File

@ -3,11 +3,7 @@ package com.wisemapping.test.rest;
import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.rest.model.RestLabel; 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.RestLabelList;
import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
@ -15,25 +11,16 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.springframework.web.client.RestTemplate;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.wisemapping.test.rest.RestHelper.BASE_REST_URL; 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.assertTrue;
import static org.testng.Assert.fail;
@Test @Test
public class RestMindmapLabelITCase { 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(); final RestLabel restLabel = new RestLabel();
restLabel.setTitle(title); restLabel.setTitle(title);
restLabel.setColor("#666666"); restLabel.setColor("#666666");
@ -92,7 +79,7 @@ public class RestMindmapLabelITCase {
return template.postForLocation(BASE_REST_URL + "/labels", createUserEntity); 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); return addNewLabel(requestHeaders, template, title, null);
} }
} }