Refactor (#2538)
This commit is contained in:
parent
89927e4620
commit
6d6b24590f
@ -3,7 +3,6 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>spring-ldap</artifactId>
|
<artifactId>spring-ldap</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -1,67 +1,67 @@
|
|||||||
package com.baeldung.ldap.client;
|
package com.baeldung.ldap.client;
|
||||||
|
|
||||||
import com.baeldung.ldap.data.service.UserService;
|
import com.baeldung.ldap.data.service.UserService;
|
||||||
import com.baeldung.ldap.javaconfig.TestConfig;
|
import com.baeldung.ldap.javaconfig.TestConfig;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ActiveProfiles("testlive")
|
@ActiveProfiles("testlive")
|
||||||
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
|
||||||
public class LdapDataRepositoryTest {
|
public class LdapDataRepositoryIntegrationTest {
|
||||||
|
|
||||||
private static final String USER2 = "TEST02";
|
private static final String USER2 = "TEST02";
|
||||||
private static final String USER3 = "TEST03";
|
private static final String USER3 = "TEST03";
|
||||||
private static final String USER4 = "TEST04";
|
private static final String USER4 = "TEST04";
|
||||||
|
|
||||||
private static final String USER2_PWD = "TEST02";
|
private static final String USER2_PWD = "TEST02";
|
||||||
private static final String USER3_PWD = "TEST03";
|
private static final String USER3_PWD = "TEST03";
|
||||||
private static final String USER4_PWD = "TEST04";
|
private static final String USER4_PWD = "TEST04";
|
||||||
|
|
||||||
private static final String SEARCH_STRING = "TEST*";
|
private static final String SEARCH_STRING = "TEST*";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLdapClient_whenCorrectCredentials_thenSuccessfulLogin() {
|
public void givenLdapClient_whenCorrectCredentials_thenSuccessfulLogin() {
|
||||||
Boolean isValid = userService.authenticate(USER3, USER3_PWD);
|
Boolean isValid = userService.authenticate(USER3, USER3_PWD);
|
||||||
assertEquals(true, isValid);
|
assertEquals(true, isValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLdapClient_whenIncorrectCredentials_thenFailedLogin() {
|
public void givenLdapClient_whenIncorrectCredentials_thenFailedLogin() {
|
||||||
Boolean isValid = userService.authenticate(USER3, USER2_PWD);
|
Boolean isValid = userService.authenticate(USER3, USER2_PWD);
|
||||||
assertEquals(false, isValid);
|
assertEquals(false, isValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLdapClient_whenCorrectSearchFilter_thenEntriesReturned() {
|
public void givenLdapClient_whenCorrectSearchFilter_thenEntriesReturned() {
|
||||||
List<String> userList = userService.search(SEARCH_STRING);
|
List<String> userList = userService.search(SEARCH_STRING);
|
||||||
assertThat(userList, Matchers.containsInAnyOrder(USER2, USER3));
|
assertThat(userList, Matchers.containsInAnyOrder(USER2, USER3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLdapClientNotExists_whenDataProvided_thenNewUserCreated() {
|
public void givenLdapClientNotExists_whenDataProvided_thenNewUserCreated() {
|
||||||
userService.create(USER4, USER4_PWD);
|
userService.create(USER4, USER4_PWD);
|
||||||
userService.authenticate(USER4, USER4_PWD);
|
userService.authenticate(USER4, USER4_PWD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLdapClientExists_whenDataProvided_thenExistingUserModified() {
|
public void givenLdapClientExists_whenDataProvided_thenExistingUserModified() {
|
||||||
userService.modify(USER2, USER3_PWD);
|
userService.modify(USER2, USER3_PWD);
|
||||||
userService.authenticate(USER2, USER3_PWD);
|
userService.authenticate(USER2, USER3_PWD);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,16 +20,16 @@ import java.time.ZonedDateTime;
|
|||||||
import static com.baeldung.weather.MetaWeatherClient.getDataByPlaceId;
|
import static com.baeldung.weather.MetaWeatherClient.getDataByPlaceId;
|
||||||
import static com.baeldung.weather.MetaWeatherClient.searchByCityName;
|
import static com.baeldung.weather.MetaWeatherClient.searchByCityName;
|
||||||
|
|
||||||
public class VertxWithRxJavaTest {
|
public class VertxWithRxJavaIntegrationTest {
|
||||||
|
|
||||||
private Vertx vertx;
|
private Vertx vertx;
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
private FileSystem fileSystem;
|
private FileSystem fileSystem;
|
||||||
private static Logger log = LoggerFactory.getLogger(VertxWithRxJavaTest.class);
|
private static Logger log = LoggerFactory.getLogger(VertxWithRxJavaIntegrationTest.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
vertx = io.vertx.reactivex.core.Vertx.vertx();
|
vertx = Vertx.vertx();
|
||||||
httpClient = vertx.createHttpClient();
|
httpClient = vertx.createHttpClient();
|
||||||
fileSystem = vertx.fileSystem();
|
fileSystem = vertx.fileSystem();
|
||||||
}
|
}
|
||||||
@ -45,18 +45,18 @@ public class VertxWithRxJavaTest {
|
|||||||
// read the file that contains one city name per line
|
// read the file that contains one city name per line
|
||||||
fileSystem
|
fileSystem
|
||||||
.rxReadFile("cities.txt").toFlowable()
|
.rxReadFile("cities.txt").toFlowable()
|
||||||
.doOnNext(buffer -> log.info("File buffer ---\n{}\n---", buffer))
|
.doOnNext(buffer -> log.info("File buffer ---\n{}\n---", buffer))
|
||||||
.flatMap(buffer -> Flowable.fromArray(buffer.toString().split("\\r?\\n")))
|
.flatMap(buffer -> Flowable.fromArray(buffer.toString().split("\\r?\\n")))
|
||||||
.doOnNext(city -> log.info("City from file: '{}'", city))
|
.doOnNext(city -> log.info("City from file: '{}'", city))
|
||||||
.filter(city -> !city.startsWith("#"))
|
.filter(city -> !city.startsWith("#"))
|
||||||
.doOnNext(city -> log.info("City that survived filtering: '{}'", city))
|
.doOnNext(city -> log.info("City that survived filtering: '{}'", city))
|
||||||
.flatMap(city -> searchByCityName(httpClient, city))
|
.flatMap(city -> searchByCityName(httpClient, city))
|
||||||
.flatMap(HttpClientResponse::toFlowable)
|
.flatMap(HttpClientResponse::toFlowable)
|
||||||
.doOnNext(buffer -> log.info("JSON of city detail: '{}'", buffer))
|
.doOnNext(buffer -> log.info("JSON of city detail: '{}'", buffer))
|
||||||
.map(extractingWoeid())
|
.map(extractingWoeid())
|
||||||
.flatMap(cityId -> getDataByPlaceId(httpClient, cityId))
|
.flatMap(cityId -> getDataByPlaceId(httpClient, cityId))
|
||||||
.flatMap(toBufferFlowable())
|
.flatMap(toBufferFlowable())
|
||||||
.doOnNext(buffer -> log.info("JSON of place detail: '{}'", buffer))
|
.doOnNext(buffer -> log.info("JSON of place detail: '{}'", buffer))
|
||||||
.map(Buffer::toJsonObject)
|
.map(Buffer::toJsonObject)
|
||||||
.map(toCityAndDayLength())
|
.map(toCityAndDayLength())
|
||||||
.subscribe(System.out::println, Throwable::printStackTrace);
|
.subscribe(System.out::println, Throwable::printStackTrace);
|
Loading…
x
Reference in New Issue
Block a user