Skip to content

Commit

Permalink
Merge pull request #318 from TikhomirovSergey/master
Browse files Browse the repository at this point in the history
0.20.22-ALPHA
  • Loading branch information
TikhomirovSergey authored Jan 30, 2022
2 parents fd120ca + f246977 commit e90ef24
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 74 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
globalVersion = '0.20.21-ALPHA'
globalVersion = '0.20.22-ALPHA'
}

subprojects {
Expand Down Expand Up @@ -33,9 +33,9 @@ subprojects {
seleniumVersion = '4.1.1'
allureVersion = '2.17.2'
jacksonVersion = '2.13.1'
mockitoVersion = '4.2.0'
springVersion = '5.3.14'
springBootVersion = '2.6.2'
mockitoVersion = '4.3.1'
springVersion = '5.3.15'
springBootVersion = '2.6.3'
globalVersion = version
}

Expand Down
2 changes: 1 addition & 1 deletion core.api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ configurations {

dependencies {
implementation group: 'org.objenesis', name: 'objenesis', version: '3.2'
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.6'
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.7'
inpath(group: 'org.hamcrest', name: 'hamcrest', version: hamcrestVersion) {
transitive = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,20 @@ static void injectValues(Object o) {

var fields2 = fields1;

dependencyInjectors.forEach(injector -> {
stream(fields2).forEach(f -> {
var m = f.getModifiers();
f.setAccessible(true);
var type = f.getType();
dependencyInjectors.forEach(injector -> stream(fields2).forEach(f -> {
var m = f.getModifiers();
f.setAccessible(true);
var type = f.getType();

try {
var val = f.get(o);
if (!isStatic(m) && !isFinal(m) && injector.toSet(f) && (type.isPrimitive() || val == null)) {
f.set(o, injector.getValueToSet(f));
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
try {
var val = f.get(o);
if (!isStatic(m) && !isFinal(m) && injector.toSet(f) && (type.isPrimitive() || val == null)) {
f.set(o, injector.getValueToSet(f));
}
});
});
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GeneralPropertiesTest {
public void clear() {
System.clearProperty("propertyA");
System.clearProperty("propertyB");
System.clearProperty("propertyС");
System.clearProperty("ConcatenatedProperty");
}

Expand All @@ -26,7 +27,8 @@ public void externalPropertiesPriorityTest() {

@Test
public void reusePropertiesTest() {
System.setProperty("ConcatenatedProperty", "${propertyA}+${propertyB}");
assertThat(new ConcatenatedProperty().get(), is("A+B"));
System.setProperty("propertyС", "с");
System.setProperty("ConcatenatedProperty", "${propertyA}+${propertyB}+${propertyС}");
assertThat(new ConcatenatedProperty().get(), is("A+B+с"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ru.tinkoff.qa.neptune.core.api.binding.Bind;
import ru.tinkoff.qa.neptune.core.api.properties.url.URLValuePropertySupplier;
import ru.tinkoff.qa.neptune.http.api.properties.end.point.DefaultEndPointOfTargetAPIProperty;
import ru.tinkoff.qa.neptune.http.api.request.RequestBuilder;
import ru.tinkoff.qa.neptune.http.api.request.RequestTuner;
import ru.tinkoff.qa.neptune.http.api.service.mapping.annotations.methods.Header;
import ru.tinkoff.qa.neptune.http.api.service.mapping.annotations.methods.HttpMethod;
Expand All @@ -18,10 +19,12 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.ClassLoader.getSystemClassLoader;
import static java.lang.reflect.Proxy.newProxyInstance;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static ru.tinkoff.qa.neptune.http.api.service.mapping.HttpServiceBindReader.getDefaultURLProperty;

Expand All @@ -30,7 +33,7 @@
* This interface is designed to be a parent of interfaces that model
* behavior of some http API.
* <p>
* Child interfaces should declare methods that return {@link ru.tinkoff.qa.neptune.http.api.request.RequestBuilder}.
* Child interfaces should declare methods that return {@link RequestBuilder}.
* These methods should describe application http API under the testing.
* Other methods should be static or they should have {@code default} modifier.
* {@code default} methods also may describe API of an applications in case when a method of an API has optional
Expand Down Expand Up @@ -73,6 +76,13 @@
*/
public interface HttpAPI<T extends HttpAPI<T>> {

@SuppressWarnings("unchecked")
private static <T extends HttpAPI<T>> T createAPI(Class<T> toCreate, Supplier<URI> uriSupplier) {
return (T) newProxyInstance(getSystemClassLoader(),
new Class[]{toCreate},
new HttpAPIProxyHandler(uriSupplier, toCreate));
}

/**
* Creates an instance of an interface that extends {@link HttpAPI}.
*
Expand All @@ -81,11 +91,9 @@ public interface HttpAPI<T extends HttpAPI<T>> {
* @param <T> is a type of resulted instance
* @return is an instance of an interface that extends {@link HttpAPI}
*/
@SuppressWarnings("unchecked")
static <T extends HttpAPI<T>> T createAPI(Class<T> toCreate, URI uri) {
return (T) newProxyInstance(getSystemClassLoader(),
new Class[]{toCreate},
new HttpAPIProxyHandler(uri, toCreate));
checkArgument(nonNull(toCreate), "Value of root URI is null");
return createAPI(toCreate, () -> uri);
}

/**
Expand Down Expand Up @@ -130,7 +138,14 @@ static <T extends HttpAPI<T>> T createAPI(Class<T> toCreate, String uriStr) {
* @return is an instance of an interface that extends {@link HttpAPI}
*/
static <T extends HttpAPI<T>> T createAPI(Class<T> toCreate, URLValuePropertySupplier urlProperty) {
return createAPI(toCreate, urlProperty.get());
checkArgument(nonNull(urlProperty), "Supplier of root URI is null");
return createAPI(toCreate, () -> {
try {
return urlProperty.get().toURI();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
});
}

/**
Expand All @@ -148,17 +163,17 @@ static <T extends HttpAPI<T>> T createAPI(Class<T> toCreate) {
}

/**
* Adds instances that define parameters of resulted objects of {@link ru.tinkoff.qa.neptune.http.api.request.RequestBuilder}
* Adds instances that define parameters of resulted objects of {@link RequestBuilder}
*
* @param requestTuners instances that define parameters of resulted objects of {@link ru.tinkoff.qa.neptune.http.api.request.RequestBuilder}
* @param requestTuners instances that define parameters of resulted objects of {@link RequestBuilder}
* @return is supposed to return self-reference
*/
T useForRequestBuilding(RequestTuner... requestTuners);

/**
* Defines a class those instance defines parameters of resulted objects of {@link ru.tinkoff.qa.neptune.http.api.request.RequestBuilder}
* Defines a class those instance defines parameters of resulted objects of {@link RequestBuilder}
*
* @param requestTuner a class those instance defines parameters of resulted objects of {@link ru.tinkoff.qa.neptune.http.api.request.RequestBuilder}
* @param requestTuner a class those instance defines parameters of resulted objects of {@link RequestBuilder}
* @return is supposed to return self-reference
*/
T useForRequestBuilding(Class<? extends RequestTuner> requestTuner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.lang.String.format;
import static java.lang.invoke.MethodHandles.lookup;
import static java.lang.invoke.MethodHandles.privateLookupIn;
import static java.util.Arrays.asList;
import static java.util.Objects.nonNull;
import static ru.tinkoff.qa.neptune.http.api.service.mapping.HttpServiceBindReader.getRequestTuners;
import static ru.tinkoff.qa.neptune.http.api.service.mapping.annotations.methods.HttpMethod.HttpMethodFactory.createRequestBuilder;
import static ru.tinkoff.qa.neptune.http.api.service.mapping.annotations.parameters.body.BodyParameterAnnotationReader.readBodies;
Expand All @@ -24,18 +26,19 @@ class HttpAPIProxyHandler implements InvocationHandler {
private static final String USE_FOR_REQUEST_BUILDING = "useForRequestBuilding";

private final List<Object> requestTuners = new LinkedList<>();
private final URI rootURI;
private final Supplier<URI> uriSupplier;

HttpAPIProxyHandler(URI rootURI, Class<? extends HttpAPI<?>> getBoundTunersFrom) {
checkNotNull(rootURI);
this.rootURI = rootURI;
requestTuners.addAll(getRequestTuners(getBoundTunersFrom));
HttpAPIProxyHandler(Supplier<URI> uriSupplier, Class<? extends HttpAPI<?>> httpAPIClazz) {
this.uriSupplier = uriSupplier;
requestTuners.addAll(getRequestTuners(httpAPIClazz));
}

@Override
@SuppressWarnings("unchecked")
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

var rootURI = uriSupplier.get();
checkState(nonNull(rootURI), "Root URI is not defined");
method.setAccessible(true);

var paramTypes = method.getParameterTypes();
Expand Down
2 changes: 1 addition & 1 deletion kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
inpath(project(":core.api")) {
transitive = false
}
api group: 'org.apache.kafka', name: 'kafka-clients', version: '3.0.0'
api group: 'org.apache.kafka', name: 'kafka-clients', version: '3.1.0'
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion
}
Expand Down
2 changes: 1 addition & 1 deletion rabbit.mq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
inpath(project(":core.api")) {
transitive = false
}
api group: 'com.rabbitmq', name: 'amqp-client', version: '5.14.0'
api group: 'com.rabbitmq', name: 'amqp-client', version: '5.14.1'
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.tinkoff.qa.neptune.retrofit2.service.setup;

import java.net.URL;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.ClassLoader.getSystemClassLoader;
Expand All @@ -17,21 +18,21 @@ private HttpServiceCreator() {
super();
}

private static Object createAPI(Class<?> toInstantiate, URL baseURL, RetrofitBuilderSupplier retrofit) {
private static Object createAPI(Class<?> toInstantiate, Supplier<URL> urlSupplier, RetrofitBuilderSupplier retrofit) {
checkNotNull(toInstantiate);
checkNotNull(baseURL);
checkNotNull(urlSupplier);
checkNotNull(retrofit);

return newProxyInstance(getSystemClassLoader(),
new Class[]{toInstantiate},
new ServiceProxyHandler(toInstantiate, baseURL, retrofit));
new ServiceProxyHandler(toInstantiate, urlSupplier, retrofit));
}

public static Object create(Class<?> toInstantiate, RetrofitBuilderSupplier retrofit) {
return createAPI(toInstantiate, getURL(toInstantiate), retrofit);
return createAPI(toInstantiate, () -> getURL(toInstantiate), retrofit);
}

public static Object create(Class<?> toInstantiate) {
return createAPI(toInstantiate, getURL(toInstantiate), getRetrofit(toInstantiate));
return createAPI(toInstantiate, () -> getURL(toInstantiate), getRetrofit(toInstantiate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.nonNull;
import static java.util.Optional.ofNullable;

final class ServiceProxyHandler implements InvocationHandler {

private static final ThreadLocal<Map<ServiceProxyHandler, Object>> instantiated = new ThreadLocal<>();

private final Class<?> toInstantiate;
private final URL baseURL;
private final Supplier<URL> urlSupplier;
private final RetrofitBuilderSupplier retrofitBuilderSupplier;

public ServiceProxyHandler(Class<?> toInstantiate, URL baseURL, RetrofitBuilderSupplier retrofitBuilderSupplier) {
public ServiceProxyHandler(Class<?> toInstantiate, Supplier<URL> urlSupplier, RetrofitBuilderSupplier retrofitBuilderSupplier) {
this.toInstantiate = toInstantiate;
this.baseURL = baseURL;
this.urlSupplier = urlSupplier;
this.retrofitBuilderSupplier = retrofitBuilderSupplier;
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
var baseURL = urlSupplier.get();
checkState(nonNull(baseURL), "Base URL is not defined");
method.setAccessible(true);

var map = ofNullable(instantiated.get())
.orElseGet(() -> {
var toRemember = new HashMap<ServiceProxyHandler, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,14 @@ selenium.functions.target.locator.frame.GetFrameSupplier.frame(int)=Фрейм c
selenium.functions.target.locator.frame.GetFrameSupplier.frame(java.lang.String)=Фрейм с именем/id {nameOrId}
#Original text = Frame {by}
selenium.functions.target.locator.frame.GetFrameSupplier.frame(org.openqa.selenium.By)=Фрейм, найденный {by}

######################## selenium.functions.target.locator.frame.parent.ParentFrameSupplier #
#Original text = Parent frame
selenium.functions.target.locator.frame.parent.ParentFrameSupplier=Родительский фрейм
#_________________________________Parameters_____________________________________
#Original text = Not present:
selenium.functions.target.locator.frame.parent.ParentFrameSupplier.errorMessageStartingOnEmptyResult=Не был получен:

######################## selenium.functions.target.locator.window.GetNewWindowSupplier #
#_________________________________Parameters_____________________________________
#Original text = Open:
Expand All @@ -358,6 +360,7 @@ selenium.functions.target.locator.window.GetNewWindowSupplier.imperative=Отк
selenium.functions.target.locator.window.GetNewWindowSupplier.newTab()=Новую вкладку
#Original text = New browser window
selenium.functions.target.locator.window.GetNewWindowSupplier.newWindow()=Новое окно

######################## selenium.functions.target.locator.window.GetWindowSupplier #
#_________________________________Parameters_____________________________________
#Original text = Time of the waiting for the browser window/tab
Expand Down
7 changes: 4 additions & 3 deletions spring.data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ configurations {
dependencies {
api(project(":database.abstractions"))
api project(':core.api')
api project(':neptune-spring-boot-starter')
inpath(project(":core.api")) {
transitive = false
}
api group: 'org.springframework.data', name: 'spring-data-commons', version: '2.6.0'
compileClasspath('org.springframework.data:spring-data-commons:2.6.1')
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion
compileClasspath(group: 'org.springframework', name: 'spring-context', version: springVersion)
compileClasspath(group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.2.21')
compileClasspath('io.projectreactor.tools:blockhound:1.0.6.RELEASE')
compileClasspath('io.projectreactor:reactor-test:3.4.13')
compileClasspath('io.projectreactor:reactor-test:3.4.14')
compileClasspath(group: 'io.micrometer', name: 'micrometer-core', version: '1.7.5')
compileClasspath(group: 'io.reactivex.rxjava3', name: 'rxjava', version: '3.1.2')
compileClasspath(group: 'com.querydsl', name: 'querydsl-core', version: '5.0.0')
Expand All @@ -37,6 +36,8 @@ dependencies {
testImplementation(group: 'com.querydsl', name: 'querydsl-core', version: '5.0.0')

bundleGeneration(group: 'com.querydsl', name: 'querydsl-core', version: '5.0.0')
testImplementation(group: 'io.micrometer', name: 'micrometer-core', version: '1.7.5')
testImplementation('org.springframework.data:spring-data-commons:2.6.1')
}

java {
Expand Down
Loading

0 comments on commit e90ef24

Please sign in to comment.