Build optimization 10.06.2017 (#2037)

* Refactor

* Refactor
This commit is contained in:
Grzegorz Piwowarek 2017-06-11 06:58:57 +02:00 committed by GitHub
parent 25c476a09b
commit dc43aec4d3
11 changed files with 65 additions and 133 deletions

View File

@ -1,4 +1,4 @@
package com.baeuldung.serialization;
package com.baeldung.serialization;
public class Address {

View File

@ -1,4 +1,4 @@
package com.baeuldung.serialization;
package com.baeldung.serialization;
import java.io.IOException;
import java.io.ObjectInputStream;

View File

@ -1,4 +1,4 @@
package com.baeuldung.serialization;
package com.baeldung.serialization;
import java.io.Serializable;
public class Person implements Serializable {

View File

@ -11,9 +11,9 @@ import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class CompletableFutureUnitTest {
public class CompletableFutureLongRunningUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(CompletableFutureUnitTest.class);
private static final Logger LOG = LoggerFactory.getLogger(CompletableFutureLongRunningUnitTest.class);
@Test

View File

@ -11,13 +11,12 @@ import org.junit.Test;
import com.baeldung.filesystem.jndi.LookupFSJNDI;
public class LookupFSJNDITest {
public class LookupFSJNDIIntegrationTest {
LookupFSJNDI fsjndi;
File file;
InitialContext ctx = null;
final String FILENAME = "test.find";
public LookupFSJNDITest() {
public LookupFSJNDIIntegrationTest() {
try {
fsjndi = new LookupFSJNDI();
} catch (NamingException e) {

View File

@ -1,4 +1,4 @@
package com.baeuldung.serialization;
package com.baeldung.serialization;
import static org.junit.Assert.assertTrue;

View File

@ -12,9 +12,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import static junit.framework.TestCase.assertEquals;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SynchronousQueueUnitTest {
public class SynchronousQueueIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(SynchronousQueueUnitTest.class);
private static final Logger LOG = LoggerFactory.getLogger(SynchronousQueueIntegrationTest.class);
@Test

View File

@ -1,12 +1,10 @@
package com.baeldung.test;
package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.Spring5Application;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5Application.class)
public class Spring5ApplicationIntegrationTest {

View File

@ -1,54 +1,52 @@
package com.baeldung.test;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.http.MediaType;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
public class LiveTest {
private static String APP_ROOT = "http://localhost:8081";
@Test
public void givenUser_whenResourceCreatedWithNullName_then400BadRequest() {
final Response response = givenAuth("user", "pass").contentType(MediaType.APPLICATION_JSON.toString()).body(resourceWithNullName()).post(APP_ROOT + "/foos");
assertEquals(400, response.getStatusCode());
}
@Test
public void givenUser_whenResourceCreated_then201Created() {
final Response response = givenAuth("user", "pass").contentType(MediaType.APPLICATION_JSON.toString()).body(resourceString()).post(APP_ROOT + "/foos");
assertEquals(201, response.getStatusCode());
}
/*@Test
public void givenUser_whenGetAllFoos_thenOK() {
final Response response = givenAuth("user", "pass").get(APP_ROOT + "/foos");
assertEquals(200, response.getStatusCode());
}*/
//
private final String resourceWithNullName() {
final String roleData = "{\"name\":null}";
return roleData;
}
private final String resourceString() {
final String roleData = "{\"name\":\"" + randomAlphabetic(8) + "\"}";
return roleData;
}
private final RequestSpecification givenAuth(String username, String password) {
return RestAssured.given().auth().preemptive().basic(username, password);
}
package com.baeldung;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.http.MediaType;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
public class LiveTest {
private static String APP_ROOT = "http://localhost:8081";
@Test
public void givenUser_whenResourceCreatedWithNullName_then400BadRequest() {
final Response response = givenAuth("user", "pass").contentType(MediaType.APPLICATION_JSON.toString()).body(resourceWithNullName()).post(APP_ROOT + "/foos");
assertEquals(400, response.getStatusCode());
}
@Test
public void givenUser_whenResourceCreated_then201Created() {
final Response response = givenAuth("user", "pass").contentType(MediaType.APPLICATION_JSON.toString()).body(resourceString()).post(APP_ROOT + "/foos");
assertEquals(201, response.getStatusCode());
}
/*@Test
public void givenUser_whenGetAllFoos_thenOK() {
final Response response = givenAuth("user", "pass").get(APP_ROOT + "/foos");
assertEquals(200, response.getStatusCode());
}*/
//
private final String resourceWithNullName() {
return "{\"name\":null}";
}
private final String resourceString() {
return "{\"name\":\"" + randomAlphabetic(8) + "\"}";
}
private final RequestSpecification givenAuth(String username, String password) {
return RestAssured.given().auth().preemptive().basic(username, password);
}
}

View File

@ -1,7 +1,5 @@
package springbootkotlin
package com.baeldung.springbootkotlin
import com.baeldung.springbootkotlin.HelloDto
import com.baeldung.springbootkotlin.KotlinDemoApplication
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
@ -14,8 +12,8 @@ import org.springframework.test.context.junit4.SpringRunner
@RunWith(SpringRunner::class)
@SpringBootTest(
classes = arrayOf(KotlinDemoApplication::class),
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
classes = arrayOf(KotlinDemoApplication::class),
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class KotlinDemoApplicationIntegrationTest {
@Autowired

View File

@ -1,61 +0,0 @@
package org.baeldung.web;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import org.baeldung.multipleauthproviders.MultipleAuthProvidersApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = MultipleAuthProvidersApplication.class)
public class MultipleAuthProvidersApplicationTests {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void givenMemUsers_whenGetPingWithValidUser_thenOk() {
ResponseEntity<String> result = makeRestCallToGetPing("memuser", "pass");
assertThat(result.getStatusCodeValue()).isEqualTo(200);
assertThat(result.getBody()).isEqualTo("OK");
}
@Test
public void givenExternalUsers_whenGetPingWithValidUser_thenOK() {
ResponseEntity<String> result = makeRestCallToGetPing("externaluser", "pass");
assertThat(result.getStatusCodeValue()).isEqualTo(200);
assertThat(result.getBody()).isEqualTo("OK");
}
@Test
public void givenAuthProviders_whenGetPingWithNoCred_then401() {
ResponseEntity<String> result = makeRestCallToGetPing();
assertThat(result.getStatusCodeValue()).isEqualTo(401);
}
@Test
public void givenAuthProviders_whenGetPingWithBadCred_then401() {
ResponseEntity<String> result = makeRestCallToGetPing("user", "bad_password");
assertThat(result.getStatusCodeValue()).isEqualTo(401);
}
private ResponseEntity<String> makeRestCallToGetPing(String username, String password) {
return restTemplate.withBasicAuth(username, password)
.getForEntity("/api/ping", String.class, Collections.emptyMap());
}
private ResponseEntity<String> makeRestCallToGetPing() {
return restTemplate.getForEntity("/api/ping", String.class, Collections.emptyMap());
}
}