You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by bo...@apache.org on 2022/12/18 19:59:32 UTC
[streampipes] 01/04: add checkstyle to streampipes-connect-container-master
This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch chore/checkstyle
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit d2fc7c8f9f6863680d0e1c9e7686a6ca4625d004
Author: bossenti <bo...@posteo.de>
AuthorDate: Sun Dec 18 15:29:59 2022 +0100
add checkstyle to streampipes-connect-container-master
---
streampipes-connect-container-master/pom.xml | 9 +-
.../master/health/AdapterHealthCheck.java | 1 +
.../master/health/AdapterOperationLock.java | 1 +
.../master/management/AdapterMasterManagement.java | 3 +-
.../master/management/DescriptionManagement.java | 81 ++---
.../master/management/GuessManagement.java | 66 ++--
.../master/management/SourcesManagement.java | 35 +-
.../master/management/UnitMasterManagement.java | 59 ++--
.../management/WorkerAdministrationManagement.java | 3 +-
.../master/management/WorkerRestClient.java | 357 +++++++++++----------
.../master/management/WorkerUrlProvider.java | 3 +-
.../connect/container/master/util/WorkerPaths.java | 2 +-
.../master/health/AdapterHealthCheckTest.java | 116 +++----
.../management/AdapterMasterManagementTest.java | 75 +++--
.../management/DescriptionManagementTest.java | 29 +-
.../master/management/SourcesManagementTest.java | 1 +
.../management/UnitMasterManagementTest.java | 172 +++++-----
.../master/management/WorkerRestClientTest.java | 146 +++++----
18 files changed, 599 insertions(+), 560 deletions(-)
diff --git a/streampipes-connect-container-master/pom.xml b/streampipes-connect-container-master/pom.xml
index 0de492280..aab185a84 100644
--- a/streampipes-connect-container-master/pom.xml
+++ b/streampipes-connect-container-master/pom.xml
@@ -17,7 +17,8 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>streampipes-parent</artifactId>
<groupId>org.apache.streampipes</groupId>
@@ -97,5 +98,11 @@
<build>
<finalName>streampipes-connect-container-master</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ </plugins>
</build>
</project>
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java
index 1704c84ce..689978fde 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java
@@ -13,6 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
*/
package org.apache.streampipes.connect.container.master.health;
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java
index 38fdd0c5a..f877e9f93 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java
@@ -13,6 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
*/
package org.apache.streampipes.connect.container.master.health;
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java
index c910ce090..965952f0d 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagement.java
@@ -18,7 +18,6 @@
package org.apache.streampipes.connect.container.master.management;
-import org.apache.commons.lang3.RandomStringUtils;
import org.apache.streampipes.commons.exceptions.NoServiceEndpointsAvailableException;
import org.apache.streampipes.commons.exceptions.SepaParseException;
import org.apache.streampipes.connect.adapter.GroundingService;
@@ -35,6 +34,8 @@ import org.apache.streampipes.resource.management.DataStreamResourceManager;
import org.apache.streampipes.resource.management.SpResourceManager;
import org.apache.streampipes.storage.api.IAdapterStorage;
import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl;
+
+import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java
index da40e4995..38d5fc555 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/DescriptionManagement.java
@@ -35,55 +35,56 @@ import java.util.Optional;
public class DescriptionManagement {
- public List<FormatDescription> getFormats() {
- Map<String, IFormat> allFormats = AdapterRegistry.getAllFormats();
+ public List<FormatDescription> getFormats() {
+ Map<String, IFormat> allFormats = AdapterRegistry.getAllFormats();
- List<FormatDescription> result = new ArrayList<>();
- for (IFormat f : allFormats.values()) {
- result.add(f.declareModel());
- }
-
- return result;
+ List<FormatDescription> result = new ArrayList<>();
+ for (IFormat f : allFormats.values()) {
+ result.add(f.declareModel());
}
- public List<AdapterDescription> getAdapters() {
- IAdapterStorage adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage();
- return adapterStorage.getAllAdapters();
- }
+ return result;
+ }
- public Optional<AdapterDescription> getAdapter(String id) {
- return getAdapters().stream()
- .filter(desc -> desc.getAppId().equals(id))
- .findFirst();
- }
+ public List<AdapterDescription> getAdapters() {
+ IAdapterStorage adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage();
+ return adapterStorage.getAllAdapters();
+ }
- public void deleteAdapterDescription(String id) throws SpRuntimeException {
- var adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage();
- var adapter = adapterStorage.getAdapter(id);
- if (!isAdapterUsed(adapter)) {
- adapterStorage.deleteAdapter(id);
- } else {
- throw new SpRuntimeException("This adapter is used by an existing instance and cannot be deleted");
- }
- }
- public String getAssets(String baseUrl) throws AdapterException {
- return WorkerRestClient.getAssets(baseUrl);
- }
+ public Optional<AdapterDescription> getAdapter(String id) {
+ return getAdapters().stream()
+ .filter(desc -> desc.getAppId().equals(id))
+ .findFirst();
+ }
- public byte[] getIconAsset(String baseUrl) throws AdapterException {
- return WorkerRestClient.getIconAsset(baseUrl);
+ public void deleteAdapterDescription(String id) throws SpRuntimeException {
+ var adapterStorage = CouchDbStorageManager.INSTANCE.getAdapterDescriptionStorage();
+ var adapter = adapterStorage.getAdapter(id);
+ if (!isAdapterUsed(adapter)) {
+ adapterStorage.deleteAdapter(id);
+ } else {
+ throw new SpRuntimeException("This adapter is used by an existing instance and cannot be deleted");
}
+ }
- public String getDocumentationAsset(String baseUrl) throws AdapterException {
- return WorkerRestClient.getDocumentationAsset(baseUrl);
- }
+ public String getAssets(String baseUrl) throws AdapterException {
+ return WorkerRestClient.getAssets(baseUrl);
+ }
- private boolean isAdapterUsed(AdapterDescription adapter) {
- var allAdapters = StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage().getAllAdapters();
+ public byte[] getIconAsset(String baseUrl) throws AdapterException {
+ return WorkerRestClient.getIconAsset(baseUrl);
+ }
- return allAdapters
- .stream()
- .anyMatch(runningAdapter -> runningAdapter.getAppId().equals(adapter.getAppId()));
- }
+ public String getDocumentationAsset(String baseUrl) throws AdapterException {
+ return WorkerRestClient.getDocumentationAsset(baseUrl);
+ }
+
+ private boolean isAdapterUsed(AdapterDescription adapter) {
+ var allAdapters = StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage().getAllAdapters();
+
+ return allAdapters
+ .stream()
+ .anyMatch(runningAdapter -> runningAdapter.getAppId().equals(adapter.getAppId()));
+ }
}
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java
index de66c5449..0caf900c7 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java
@@ -18,13 +18,6 @@
package org.apache.streampipes.connect.container.master.management;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.fluent.Response;
-import org.apache.http.entity.ContentType;
-import org.apache.http.util.EntityUtils;
import org.apache.streampipes.commons.exceptions.NoServiceEndpointsAvailableException;
import org.apache.streampipes.commons.exceptions.SpConfigurationException;
import org.apache.streampipes.connect.adapter.model.pipeline.AdapterEventPreviewPipeline;
@@ -36,6 +29,14 @@ import org.apache.streampipes.model.connect.guess.AdapterEventPreview;
import org.apache.streampipes.model.connect.guess.GuessSchema;
import org.apache.streampipes.model.connect.guess.GuessTypeInfo;
import org.apache.streampipes.serializers.json.JacksonSerializer;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.client.fluent.Response;
+import org.apache.http.entity.ContentType;
+import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,39 +45,40 @@ import java.util.Map;
public class GuessManagement {
- private static Logger LOG = LoggerFactory.getLogger(GuessManagement.class);
- private WorkerUrlProvider workerUrlProvider;
+ private static Logger logger = LoggerFactory.getLogger(GuessManagement.class);
+ private WorkerUrlProvider workerUrlProvider;
- public GuessManagement() {
- this.workerUrlProvider = new WorkerUrlProvider();
- }
+ public GuessManagement() {
+ this.workerUrlProvider = new WorkerUrlProvider();
+ }
- public GuessSchema guessSchema(AdapterDescription adapterDescription) throws ParseException, WorkerAdapterException, NoServiceEndpointsAvailableException, IOException {
- String workerUrl = workerUrlProvider.getWorkerBaseUrl(adapterDescription.getAppId());
+ public GuessSchema guessSchema(AdapterDescription adapterDescription)
+ throws ParseException, WorkerAdapterException, NoServiceEndpointsAvailableException, IOException {
+ String workerUrl = workerUrlProvider.getWorkerBaseUrl(adapterDescription.getAppId());
- workerUrl = workerUrl + WorkerPaths.getGuessSchemaPath();
+ workerUrl = workerUrl + WorkerPaths.getGuessSchemaPath();
- ObjectMapper mapper = JacksonSerializer.getObjectMapper();
- String ad = mapper.writeValueAsString(adapterDescription);
- LOG.info("Guess schema at: " + workerUrl);
- Response requestResponse = Request.Post(workerUrl)
- .bodyString(ad, ContentType.APPLICATION_JSON)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute();
+ ObjectMapper mapper = JacksonSerializer.getObjectMapper();
+ String ad = mapper.writeValueAsString(adapterDescription);
+ logger.info("Guess schema at: " + workerUrl);
+ Response requestResponse = Request.Post(workerUrl)
+ .bodyString(ad, ContentType.APPLICATION_JSON)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute();
- HttpResponse httpResponse = requestResponse.returnResponse();
- String responseString = EntityUtils.toString(httpResponse.getEntity());
+ HttpResponse httpResponse = requestResponse.returnResponse();
+ String responseString = EntityUtils.toString(httpResponse.getEntity());
- if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- return mapper.readValue(responseString, GuessSchema.class);
- } else {
- var exception = mapper.readValue(responseString, SpConfigurationException.class);
- throw new WorkerAdapterException(exception.getMessage(), exception.getCause());
- }
+ if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+ return mapper.readValue(responseString, GuessSchema.class);
+ } else {
+ var exception = mapper.readValue(responseString, SpConfigurationException.class);
+ throw new WorkerAdapterException(exception.getMessage(), exception.getCause());
}
+ }
public Map<String, GuessTypeInfo> performAdapterEventPreview(AdapterEventPreview previewRequest) {
- return new AdapterEventPreviewPipeline(previewRequest).makePreview();
+ return new AdapterEventPreviewPipeline(previewRequest).makePreview();
}
}
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java
index 6deb54246..e2cbd9a71 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/SourcesManagement.java
@@ -32,6 +32,7 @@ import org.apache.streampipes.model.schema.EventSchema;
import org.apache.streampipes.resource.management.secret.SecretProvider;
import org.apache.streampipes.sdk.helpers.SupportedProtocols;
import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,6 +54,23 @@ public class SourcesManagement {
this(new AdapterInstanceStorageImpl());
}
+ public static SpDataStream updateDataStream(AdapterDescription adapterDescription,
+ SpDataStream oldDataStream) {
+
+ oldDataStream.setName(adapterDescription.getName());
+//
+// // Update event schema
+ EventSchema newEventSchema;
+ if (adapterDescription instanceof AdapterStreamDescription) {
+ newEventSchema = ((AdapterStreamDescription) adapterDescription).getDataStream().getEventSchema();
+ } else {
+ newEventSchema = ((AdapterSetDescription) adapterDescription).getDataSet().getEventSchema();
+ }
+ oldDataStream.setEventSchema(newEventSchema);
+
+ return oldDataStream;
+ }
+
public void addSetAdapter(SpDataSet dataSet) throws AdapterException, NoServiceEndpointsAvailableException {
AdapterSetDescription ad = (AdapterSetDescription) getAndDecryptAdapter(dataSet.getCorrespondingAdapterId());
@@ -112,23 +130,6 @@ public class SourcesManagement {
return ds;
}
- public static SpDataStream updateDataStream(AdapterDescription adapterDescription,
- SpDataStream oldDataStream) {
-
- oldDataStream.setName(adapterDescription.getName());
-//
-// // Update event schema
- EventSchema newEventSchema;
- if (adapterDescription instanceof AdapterStreamDescription) {
- newEventSchema = ((AdapterStreamDescription) adapterDescription).getDataStream().getEventSchema();
- } else {
- newEventSchema = ((AdapterSetDescription) adapterDescription).getDataSet().getEventSchema();
- }
- oldDataStream.setEventSchema(newEventSchema);
-
- return oldDataStream;
- }
-
private AdapterDescription getAndDecryptAdapter(String adapterId) {
AdapterDescription adapter = this.adapterInstanceStorage.getAdapter(adapterId);
SecretProvider.getDecryptionService().apply(adapter);
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java
index 82a0c2265..fd9ff90aa 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagement.java
@@ -18,11 +18,12 @@
package org.apache.streampipes.connect.container.master.management;
-import com.github.jqudt.Unit;
-import com.google.gson.Gson;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.model.connect.unit.UnitDescription;
import org.apache.streampipes.units.UnitProvider;
+
+import com.github.jqudt.Unit;
+import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,37 +33,39 @@ import java.util.List;
public class UnitMasterManagement {
- private static final Logger logger = LoggerFactory.getLogger(UnitMasterManagement.class);
- private Gson gson;
+ private static final Logger logger = LoggerFactory.getLogger(UnitMasterManagement.class);
+ private Gson gson;
- public UnitMasterManagement() {
- gson = new Gson();
- }
-
- public String getFittingUnits(UnitDescription unitDescription) throws AdapterException {
- List<UnitDescription> unitDescriptionList = new LinkedList<>();
- Unit unit;
+ public UnitMasterManagement() {
+ gson = new Gson();
+ }
- if(unitDescription.getResource() == null) throw new AdapterException("The resource cannot be null");
- try {
- unit = UnitProvider.INSTANCE.getUnit(unitDescription.getResource());
- } catch (IllegalStateException e) {
- throw new AdapterException("Invalid URI: " + unitDescription.getResource());
- }
- List<Unit> units = UnitProvider.INSTANCE.getUnitsByType(unit.getType());
+ public String getFittingUnits(UnitDescription unitDescription) throws AdapterException {
+ List<UnitDescription> unitDescriptionList = new LinkedList<>();
+ Unit unit;
+ if (unitDescription.getResource() == null) {
+ throw new AdapterException("The resource cannot be null");
+ }
+ try {
+ unit = UnitProvider.INSTANCE.getUnit(unitDescription.getResource());
+ } catch (IllegalStateException e) {
+ throw new AdapterException("Invalid URI: " + unitDescription.getResource());
+ }
+ List<Unit> units = UnitProvider.INSTANCE.getUnitsByType(unit.getType());
- for ( Iterator iter = units.iterator(); iter.hasNext(); ) {
- Unit unitTmp = (Unit) iter.next();
- try {
- UnitDescription unitDescriptionTmp = new UnitDescription(unitTmp.getResource().toString(), unitTmp.getLabel());
- unitDescriptionList.add(unitDescriptionTmp);
- } catch (NullPointerException e) {
- logger.error("Unit has no resource and/or Label");
- }
- }
- return gson.toJson(unitDescriptionList);
+ for (Iterator iter = units.iterator(); iter.hasNext(); ) {
+ Unit unitTmp = (Unit) iter.next();
+ try {
+ UnitDescription unitDescriptionTmp = new UnitDescription(unitTmp.getResource().toString(), unitTmp.getLabel());
+ unitDescriptionList.add(unitDescriptionTmp);
+ } catch (NullPointerException e) {
+ logger.error("Unit has no resource and/or Label");
+ }
}
+ return gson.toJson(unitDescriptionList);
+ }
+
}
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java
index 9a5455391..3b6018776 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java
@@ -6,13 +6,14 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
*/
package org.apache.streampipes.connect.container.master.management;
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java
index 241b93f51..6503f92f3 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java
@@ -18,11 +18,6 @@
package org.apache.streampipes.connect.container.master.management;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.entity.ContentType;
import org.apache.streampipes.commons.exceptions.SpConfigurationException;
import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.container.master.util.WorkerPaths;
@@ -37,6 +32,12 @@ import org.apache.streampipes.serializers.json.JacksonSerializer;
import org.apache.streampipes.storage.api.IAdapterStorage;
import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl;
import org.apache.streampipes.storage.management.StorageDispatcher;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,219 +50,221 @@ import java.util.List;
*/
public class WorkerRestClient {
- private static final Logger logger = LoggerFactory.getLogger(WorkerRestClient.class);
-
- public static void invokeStreamAdapter(String endpointUrl,
- String elementId) throws AdapterException {
- AdapterStreamDescription adapterStreamDescription = (AdapterStreamDescription) getAndDecryptAdapter(elementId);
- String url = endpointUrl + WorkerPaths.getStreamInvokePath();
+ private static final Logger logger = LoggerFactory.getLogger(WorkerRestClient.class);
- startAdapter(url, adapterStreamDescription);
- updateStreamAdapterStatus(adapterStreamDescription.getElementId(), true);
- }
+ public static void invokeStreamAdapter(String endpointUrl,
+ String elementId) throws AdapterException {
+ AdapterStreamDescription adapterStreamDescription = (AdapterStreamDescription) getAndDecryptAdapter(elementId);
+ String url = endpointUrl + WorkerPaths.getStreamInvokePath();
- public static void stopStreamAdapter(String baseUrl,
- AdapterStreamDescription adapterStreamDescription) throws AdapterException {
- String url = baseUrl + WorkerPaths.getStreamStopPath();
+ startAdapter(url, adapterStreamDescription);
+ updateStreamAdapterStatus(adapterStreamDescription.getElementId(), true);
+ }
- AdapterDescription ad = getAdapterDescriptionById(new AdapterInstanceStorageImpl(), adapterStreamDescription.getElementId());
-
- stopAdapter(ad, url);
- updateStreamAdapterStatus(adapterStreamDescription.getElementId(), false);
- }
+ public static void stopStreamAdapter(String baseUrl,
+ AdapterStreamDescription adapterStreamDescription) throws AdapterException {
+ String url = baseUrl + WorkerPaths.getStreamStopPath();
- public static void invokeSetAdapter(String endpointUrl,
- AdapterSetDescription adapterSetDescription) throws AdapterException {
- String url = endpointUrl + WorkerPaths.getSetInvokePath();
+ AdapterDescription ad =
+ getAdapterDescriptionById(new AdapterInstanceStorageImpl(), adapterStreamDescription.getElementId());
- startAdapter(url, adapterSetDescription);
- }
+ stopAdapter(ad, url);
+ updateStreamAdapterStatus(adapterStreamDescription.getElementId(), false);
+ }
- public static void stopSetAdapter(String baseUrl,
+ public static void invokeSetAdapter(String endpointUrl,
AdapterSetDescription adapterSetDescription) throws AdapterException {
- String url = baseUrl + WorkerPaths.getSetStopPath();
+ String url = endpointUrl + WorkerPaths.getSetInvokePath();
- stopAdapter(adapterSetDescription, url);
- }
+ startAdapter(url, adapterSetDescription);
+ }
- public static List<AdapterDescription> getAllRunningAdapterInstanceDescriptions(String url) throws AdapterException {
- try {
- logger.info("Requesting all running adapter description instances: " + url);
+ public static void stopSetAdapter(String baseUrl,
+ AdapterSetDescription adapterSetDescription) throws AdapterException {
+ String url = baseUrl + WorkerPaths.getSetStopPath();
- String responseString = Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asString();
+ stopAdapter(adapterSetDescription, url);
+ }
- List<AdapterDescription> result = JacksonSerializer.getObjectMapper().readValue(responseString, List.class);
+ public static List<AdapterDescription> getAllRunningAdapterInstanceDescriptions(String url) throws AdapterException {
+ try {
+ logger.info("Requesting all running adapter description instances: " + url);
- return result;
- } catch (IOException e) {
- logger.error("List of running adapters could not be fetched", e);
- throw new AdapterException("List of running adapters could not be fetched from: " + url);
- }
- }
+ String responseString = Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asString();
- public static void startAdapter(String url,
- AdapterDescription ad) throws AdapterException {
- logger.info("Trying to start adapter on endpoint {} ", url);
- triggerAdapterStateChange(ad, url, "started");
+ List<AdapterDescription> result = JacksonSerializer.getObjectMapper().readValue(responseString, List.class);
+
+ return result;
+ } catch (IOException e) {
+ logger.error("List of running adapters could not be fetched", e);
+ throw new AdapterException("List of running adapters could not be fetched from: " + url);
}
+ }
+ public static void startAdapter(String url,
+ AdapterDescription ad) throws AdapterException {
+ logger.info("Trying to start adapter on endpoint {} ", url);
+ triggerAdapterStateChange(ad, url, "started");
+ }
- public static void stopAdapter(AdapterDescription ad,
- String url) throws AdapterException {
- logger.info("Trying to stop adapter on endpoint {} ", url);
- triggerAdapterStateChange(ad, url, "stopped");
- }
+ public static void stopAdapter(AdapterDescription ad,
+ String url) throws AdapterException {
- private static void triggerAdapterStateChange(AdapterDescription ad,
- String url,
- String action) throws AdapterException {
- try {
- String adapterDescription = JacksonSerializer.getObjectMapper().writeValueAsString(ad);
+ logger.info("Trying to stop adapter on endpoint {} ", url);
+ triggerAdapterStateChange(ad, url, "stopped");
+ }
- var response = triggerPost(url, adapterDescription);
- var responseString = getResponseBody(response);
+ private static void triggerAdapterStateChange(AdapterDescription ad,
+ String url,
+ String action) throws AdapterException {
+ try {
+ String adapterDescription = JacksonSerializer.getObjectMapper().writeValueAsString(ad);
- if (response.getStatusLine().getStatusCode() != 200) {
- var exception = getSerializer().readValue(responseString, AdapterException.class);
- throw new AdapterException(exception.getMessage(), exception.getCause());
- }
+ var response = triggerPost(url, adapterDescription);
+ var responseString = getResponseBody(response);
- logger.info("Adapter {} on endpoint: " + url + " with Response: " + responseString);
+ if (response.getStatusLine().getStatusCode() != 200) {
+ var exception = getSerializer().readValue(responseString, AdapterException.class);
+ throw new AdapterException(exception.getMessage(), exception.getCause());
+ }
- } catch (IOException e) {
- logger.error("Adapter was not {} successfully", action, e);
- throw new AdapterException("Adapter was not " + action + " successfully with url " + url, e);
- }
- }
+ logger.info("Adapter {} on endpoint: " + url + " with Response: " + responseString);
- private static String getResponseBody(HttpResponse response) throws IOException {
- return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ logger.error("Adapter was not {} successfully", action, e);
+ throw new AdapterException("Adapter was not " + action + " successfully with url " + url, e);
}
-
- private static HttpResponse triggerPost(String url,
- String payload) throws IOException {
- return Request.Post(url)
+ }
+
+ private static String getResponseBody(HttpResponse response) throws IOException {
+ return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
+ }
+
+ private static HttpResponse triggerPost(String url,
+ String payload) throws IOException {
+ return Request.Post(url)
+ .bodyString(payload, ContentType.APPLICATION_JSON)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnResponse();
+ }
+
+ public static RuntimeOptionsResponse getConfiguration(String workerEndpoint,
+ String appId,
+ RuntimeOptionsRequest runtimeOptionsRequest)
+ throws AdapterException, SpConfigurationException {
+ String url = workerEndpoint + WorkerPaths.getRuntimeResolvablePath(appId);
+
+ try {
+ String payload = JacksonSerializer.getObjectMapper().writeValueAsString(runtimeOptionsRequest);
+ var response = Request.Post(url)
.bodyString(payload, ContentType.APPLICATION_JSON)
.connectTimeout(1000)
.socketTimeout(100000)
- .execute().returnResponse();
- }
-
- public static RuntimeOptionsResponse getConfiguration(String workerEndpoint,
- String appId,
- RuntimeOptionsRequest runtimeOptionsRequest) throws AdapterException, SpConfigurationException {
- String url = workerEndpoint + WorkerPaths.getRuntimeResolvablePath(appId);
-
- try {
- String payload = JacksonSerializer.getObjectMapper().writeValueAsString(runtimeOptionsRequest);
- var response = Request.Post(url)
- .bodyString(payload, ContentType.APPLICATION_JSON)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute()
- .returnResponse();
-
- String responseString = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
-
- if (response.getStatusLine().getStatusCode() == 200) {
- return getSerializer().readValue(responseString, RuntimeOptionsResponse.class);
- } else {
- var exception = getSerializer().readValue(responseString, SpConfigurationException.class);
- throw new SpConfigurationException(exception.getMessage(), exception.getCause());
- }
- } catch (IOException e) {
- e.printStackTrace();
- throw new AdapterException("Could not resolve runtime configurations from " + url);
- }
- }
-
- public static String getAssets(String workerPath) throws AdapterException {
- String url = workerPath + "/assets";
- logger.info("Trying to Assets from endpoint: " + url);
-
- try {
- return Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asString();
- } catch (IOException e) {
- logger.error(e.getMessage());
- throw new AdapterException("Could not get assets endpoint: " + url);
- }
-
+ .execute()
+ .returnResponse();
+
+ String responseString = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
+
+ if (response.getStatusLine().getStatusCode() == 200) {
+ return getSerializer().readValue(responseString, RuntimeOptionsResponse.class);
+ } else {
+ var exception = getSerializer().readValue(responseString, SpConfigurationException.class);
+ throw new SpConfigurationException(exception.getMessage(), exception.getCause());
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new AdapterException("Could not resolve runtime configurations from " + url);
}
+ }
- public static byte[] getIconAsset(String baseUrl) throws AdapterException {
- String url = baseUrl + "/assets/icon";
-
- try {
- byte[] responseString = Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asBytes();
- return responseString;
- } catch (IOException e) {
- logger.error(e.getMessage());
- throw new AdapterException("Could not get icon endpoint: " + url);
- }
- }
+ public static String getAssets(String workerPath) throws AdapterException {
+ String url = workerPath + "/assets";
+ logger.info("Trying to Assets from endpoint: " + url);
- public static String getDocumentationAsset(String baseUrl) throws AdapterException {
- String url = baseUrl + "/assets/documentation";
-
- try {
- return Request.Get(url)
- .connectTimeout(1000)
- .socketTimeout(100000)
- .execute().returnContent().asString();
- } catch (IOException e) {
- logger.error(e.getMessage());
- throw new AdapterException("Could not get documentation endpoint: " + url);
- }
+ try {
+ return Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asString();
+ } catch (IOException e) {
+ logger.error(e.getMessage());
+ throw new AdapterException("Could not get assets endpoint: " + url);
}
+ }
- private static AdapterDescription getAdapterDescriptionById(AdapterInstanceStorageImpl adapterStorage, String id) {
- AdapterDescription adapterDescription = null;
- List<AdapterDescription> allAdapters = adapterStorage.getAllAdapters();
- for (AdapterDescription a : allAdapters) {
- if (a.getElementId().endsWith(id)) {
- adapterDescription = a;
- }
- }
+ public static byte[] getIconAsset(String baseUrl) throws AdapterException {
+ String url = baseUrl + "/assets/icon";
- return adapterDescription;
+ try {
+ byte[] responseString = Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asBytes();
+ return responseString;
+ } catch (IOException e) {
+ logger.error(e.getMessage());
+ throw new AdapterException("Could not get icon endpoint: " + url);
}
+ }
- private static void updateStreamAdapterStatus(String adapterId,
- boolean running) {
- AdapterStreamDescription adapter = (AdapterStreamDescription) getAndDecryptAdapter(adapterId);
- adapter.setRunning(running);
- encryptAndUpdateAdapter(adapter);
- }
+ public static String getDocumentationAsset(String baseUrl) throws AdapterException {
+ String url = baseUrl + "/assets/documentation";
- private static void encryptAndUpdateAdapter(AdapterDescription adapter) {
- AdapterDescription encryptedDescription = new Cloner().adapterDescription(adapter);
- SecretProvider.getEncryptionService().apply(encryptedDescription);
- getAdapterStorage().updateAdapter(encryptedDescription);
+ try {
+ return Request.Get(url)
+ .connectTimeout(1000)
+ .socketTimeout(100000)
+ .execute().returnContent().asString();
+ } catch (IOException e) {
+ logger.error(e.getMessage());
+ throw new AdapterException("Could not get documentation endpoint: " + url);
}
+ }
- private static AdapterDescription getAndDecryptAdapter(String adapterId) {
- AdapterDescription adapter = getAdapterStorage().getAdapter(adapterId);
- SecretProvider.getDecryptionService().apply(adapter);
- return adapter;
- }
- private static IAdapterStorage getAdapterStorage() {
- return StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage();
+ private static AdapterDescription getAdapterDescriptionById(AdapterInstanceStorageImpl adapterStorage, String id) {
+ AdapterDescription adapterDescription = null;
+ List<AdapterDescription> allAdapters = adapterStorage.getAllAdapters();
+ for (AdapterDescription a : allAdapters) {
+ if (a.getElementId().endsWith(id)) {
+ adapterDescription = a;
+ }
}
- private static ObjectMapper getSerializer() {
- return JacksonSerializer.getObjectMapper();
- }
+ return adapterDescription;
+ }
+
+ private static void updateStreamAdapterStatus(String adapterId,
+ boolean running) {
+ AdapterStreamDescription adapter = (AdapterStreamDescription) getAndDecryptAdapter(adapterId);
+ adapter.setRunning(running);
+ encryptAndUpdateAdapter(adapter);
+ }
+
+ private static void encryptAndUpdateAdapter(AdapterDescription adapter) {
+ AdapterDescription encryptedDescription = new Cloner().adapterDescription(adapter);
+ SecretProvider.getEncryptionService().apply(encryptedDescription);
+ getAdapterStorage().updateAdapter(encryptedDescription);
+ }
+
+ private static AdapterDescription getAndDecryptAdapter(String adapterId) {
+ AdapterDescription adapter = getAdapterStorage().getAdapter(adapterId);
+ SecretProvider.getDecryptionService().apply(adapter);
+ return adapter;
+ }
+
+ private static IAdapterStorage getAdapterStorage() {
+ return StorageDispatcher.INSTANCE.getNoSqlStore().getAdapterInstanceStorage();
+ }
+
+ private static ObjectMapper getSerializer() {
+ return JacksonSerializer.getObjectMapper();
+ }
}
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java
index 56868784e..7968e9379 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerUrlProvider.java
@@ -24,7 +24,8 @@ import org.apache.streampipes.svcdiscovery.api.model.SpServiceUrlProvider;
public class WorkerUrlProvider {
- public WorkerUrlProvider() {}
+ public WorkerUrlProvider() {
+ }
public String getWorkerUrl(String appId) throws NoServiceEndpointsAvailableException {
return getEndpointGenerator(appId).getEndpointResourceUrl();
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java
index 1a4882893..b7dab1032 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/util/WorkerPaths.java
@@ -37,7 +37,7 @@ public class WorkerPaths {
}
public static String getSetInvokePath() {
- return WorkerMainPath + "/set/invoke";
+ return WorkerMainPath + "/set/invoke";
}
public static String getSetStopPath() {
diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java
index a74de380c..12b7eb303 100644
--- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java
+++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheckTest.java
@@ -24,6 +24,7 @@ import org.apache.streampipes.model.connect.adapter.AdapterStreamDescription;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.sdk.builder.adapter.SpecificDataStreamAdapterBuilder;
import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl;
+
import org.junit.Test;
import java.util.HashMap;
@@ -40,81 +41,82 @@ import static org.powermock.api.mockito.PowerMockito.when;
public class AdapterHealthCheckTest {
- private final String testElementId = "testElementId";
+ private final String testElementId = "testElementId";
- @Test
- public void getAllRunningInstancesAdapterDescriptions() {
- AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
- when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList());
+ @Test
+ public void getAllRunningInstancesAdapterDescriptions() {
+ AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
+ when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList());
- AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(adapterStorage, null);
- Map<String, AdapterDescription> result = adapterHealthCheck.getAllRunningInstancesAdapterDescriptions();
+ AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(adapterStorage, null);
+ Map<String, AdapterDescription> result = adapterHealthCheck.getAllRunningInstancesAdapterDescriptions();
- assertNotNull(result);
- assertEquals(1, result.keySet().size());
- assertEquals(getAdapterDescriptionList().get(0), result.get(testElementId));
- }
+ assertNotNull(result);
+ assertEquals(1, result.keySet().size());
+ assertEquals(getAdapterDescriptionList().get(0), result.get(testElementId));
+ }
- @Test
- public void getAllWorkersWithAdapters() {
- AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
- when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList());
+ @Test
+ public void getAllWorkersWithAdapters() {
+ AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
+ when(adapterStorage.getAllAdapters()).thenReturn(getAdapterDescriptionList());
- AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, null);
- Map<String, List<AdapterDescription>> result = adapterHealthCheck.getAllWorkersWithAdapters(getAdapterDescriptionMap());
+ AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, null);
+ Map<String, List<AdapterDescription>> result =
+ adapterHealthCheck.getAllWorkersWithAdapters(getAdapterDescriptionMap());
- assertNotNull(result);
- assertEquals(1, result.keySet().size());
- String selectedEndpointUrl = "http://test.de";
- assertEquals(1, result.get(selectedEndpointUrl).size());
- assertEquals(getAdapterDescriptionList().get(0), result.get(selectedEndpointUrl).get(0));
- }
+ assertNotNull(result);
+ assertEquals(1, result.keySet().size());
+ String selectedEndpointUrl = "http://test.de";
+ assertEquals(1, result.get(selectedEndpointUrl).size());
+ assertEquals(getAdapterDescriptionList().get(0), result.get(selectedEndpointUrl).get(0));
+ }
- @Test
- public void recoverRunningAdaptersTest() throws AdapterException {
- AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class);
- AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock);
+ @Test
+ public void recoverRunningAdaptersTest() throws AdapterException {
+ AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class);
+ AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock);
- adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(true));
+ adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(true));
- verify(adapterMasterManagementMock, times(1)).startStreamAdapter(any());
- }
+ verify(adapterMasterManagementMock, times(1)).startStreamAdapter(any());
+ }
- @Test
- public void recoverStoppedAdaptersTest() throws AdapterException {
- AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class);
- AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock);
+ @Test
+ public void recoverStoppedAdaptersTest() throws AdapterException {
+ AdapterMasterManagement adapterMasterManagementMock = mock(AdapterMasterManagement.class);
+ AdapterHealthCheck adapterHealthCheck = new AdapterHealthCheck(null, adapterMasterManagementMock);
- adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(false));
+ adapterHealthCheck.recoverAdapters(getAdaptersToRecoverData(false));
- verify(adapterMasterManagementMock, times(0)).startStreamAdapter(any());
- }
+ verify(adapterMasterManagementMock, times(0)).startStreamAdapter(any());
+ }
- private Map<String, AdapterDescription> getAdaptersToRecoverData(boolean isRunning) {
- Map<String, AdapterDescription> adaptersToRecover = new HashMap<>();
- AdapterStreamDescription ad = SpecificDataStreamAdapterBuilder.create("").build();
- ad.setRunning(isRunning);
- adaptersToRecover.put("", ad);
- return adaptersToRecover;
- }
+ private Map<String, AdapterDescription> getAdaptersToRecoverData(boolean isRunning) {
+ Map<String, AdapterDescription> adaptersToRecover = new HashMap<>();
+ AdapterStreamDescription ad = SpecificDataStreamAdapterBuilder.create("").build();
+ ad.setRunning(isRunning);
+ adaptersToRecover.put("", ad);
+ return adaptersToRecover;
+ }
- private List<AdapterDescription> getAdapterDescriptionList() {
+ private List<AdapterDescription> getAdapterDescriptionList() {
- SpecificAdapterStreamDescription adapterStreamDescription = SpecificDataStreamAdapterBuilder
- .create("testAppId", "Test Adapter", "")
- .elementId(testElementId)
- .build();
- adapterStreamDescription.setSelectedEndpointUrl("http://test.de");
+ SpecificAdapterStreamDescription adapterStreamDescription = SpecificDataStreamAdapterBuilder
+ .create("testAppId", "Test Adapter", "")
+ .elementId(testElementId)
+ .build();
+ adapterStreamDescription.setSelectedEndpointUrl("http://test.de");
- return List.of(adapterStreamDescription);
- }
+ return List.of(adapterStreamDescription);
+ }
- private Map<String, AdapterDescription> getAdapterDescriptionMap() {
- Map<String, AdapterDescription> result = new HashMap<>();
- result.put(testElementId, getAdapterDescriptionList().get(0));
+ private Map<String, AdapterDescription> getAdapterDescriptionMap() {
+ Map<String, AdapterDescription> result = new HashMap<>();
+ result.put(testElementId, getAdapterDescriptionList().get(0));
- return result;
- }
+ return result;
+ }
}
\ No newline at end of file
diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java
index 00826a687..108988e36 100644
--- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java
+++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/AdapterMasterManagementTest.java
@@ -23,6 +23,7 @@ import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.connect.adapter.GenericAdapterStreamDescription;
import org.apache.streampipes.resource.management.AdapterResourceManager;
import org.apache.streampipes.storage.couchdb.impl.AdapterInstanceStorageImpl;
+
import org.junit.Test;
import java.util.Arrays;
@@ -34,52 +35,56 @@ import static org.mockito.Mockito.when;
public class AdapterMasterManagementTest {
- @Test(expected = AdapterException.class)
- public void getAdapterFailNull() throws AdapterException {
- AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
- AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
- when(adapterStorage.getAllAdapters()).thenReturn(null);
+ @Test(expected = AdapterException.class)
+ public void getAdapterFailNull() throws AdapterException {
+ AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
+ AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
+ when(adapterStorage.getAllAdapters()).thenReturn(null);
- AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null);
+ AdapterMasterManagement adapterMasterManagement =
+ new AdapterMasterManagement(adapterStorage, resourceManager, null);
- adapterMasterManagement.getAdapter("id2");
- }
+ adapterMasterManagement.getAdapter("id2");
+ }
- @Test(expected = AdapterException.class)
- public void getAdapterFail() throws AdapterException {
- List<AdapterDescription> adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription());
- AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
- AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
- when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions);
+ @Test(expected = AdapterException.class)
+ public void getAdapterFail() throws AdapterException {
+ List<AdapterDescription> adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription());
+ AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
+ AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
+ when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions);
- AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null);
+ AdapterMasterManagement adapterMasterManagement =
+ new AdapterMasterManagement(adapterStorage, resourceManager, null);
- adapterMasterManagement.getAdapter("id2");
- }
+ adapterMasterManagement.getAdapter("id2");
+ }
- @Test
- public void getAllAdaptersSuccess() throws AdapterException {
- List<AdapterDescription> adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription());
- AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
- AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
- when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions);
+ @Test
+ public void getAllAdaptersSuccess() throws AdapterException {
+ List<AdapterDescription> adapterDescriptions = Arrays.asList(new GenericAdapterStreamDescription());
+ AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
+ AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
+ when(adapterStorage.getAllAdapters()).thenReturn(adapterDescriptions);
- AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null);
+ AdapterMasterManagement adapterMasterManagement =
+ new AdapterMasterManagement(adapterStorage, resourceManager, null);
- List<AdapterDescription> result = adapterMasterManagement.getAllAdapterInstances();
+ List<AdapterDescription> result = adapterMasterManagement.getAllAdapterInstances();
- assertEquals(1, result.size());
- }
+ assertEquals(1, result.size());
+ }
- @Test(expected = AdapterException.class)
- public void getAllAdaptersFail() throws AdapterException {
- AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
- AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
- when(adapterStorage.getAllAdapters()).thenReturn(null);
+ @Test(expected = AdapterException.class)
+ public void getAllAdaptersFail() throws AdapterException {
+ AdapterInstanceStorageImpl adapterStorage = mock(AdapterInstanceStorageImpl.class);
+ AdapterResourceManager resourceManager = mock(AdapterResourceManager.class);
+ when(adapterStorage.getAllAdapters()).thenReturn(null);
- AdapterMasterManagement adapterMasterManagement = new AdapterMasterManagement(adapterStorage, resourceManager, null);
+ AdapterMasterManagement adapterMasterManagement =
+ new AdapterMasterManagement(adapterStorage, resourceManager, null);
- adapterMasterManagement.getAllAdapterInstances();
+ adapterMasterManagement.getAllAdapterInstances();
- }
+ }
}
diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java
index 4a470fbd8..bd4ca43c5 100644
--- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java
+++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/DescriptionManagementTest.java
@@ -22,6 +22,7 @@ import org.apache.streampipes.connect.adapter.AdapterRegistry;
import org.apache.streampipes.connect.adapter.format.json.arraykey.JsonFormat;
import org.apache.streampipes.connect.api.IFormat;
import org.apache.streampipes.model.connect.grounding.FormatDescription;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@@ -38,27 +39,27 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ AdapterRegistry.class })
+@PrepareForTest({AdapterRegistry.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
public class DescriptionManagementTest {
- @Test
- public void getFormats() {
- Map<String, IFormat> allFormats = new HashMap<>();
- allFormats.put(JsonFormat.ID, new JsonFormat());
+ @Test
+ public void getFormats() {
+ Map<String, IFormat> allFormats = new HashMap<>();
+ allFormats.put(JsonFormat.ID, new JsonFormat());
- PowerMockito.mockStatic(AdapterRegistry.class);
- Mockito.when(AdapterRegistry.getAllFormats())
- .thenReturn(allFormats);
+ PowerMockito.mockStatic(AdapterRegistry.class);
+ Mockito.when(AdapterRegistry.getAllFormats())
+ .thenReturn(allFormats);
- DescriptionManagement descriptionManagement = new DescriptionManagement();
+ DescriptionManagement descriptionManagement = new DescriptionManagement();
- List<FormatDescription> result = descriptionManagement.getFormats();
+ List<FormatDescription> result = descriptionManagement.getFormats();
- assertNotNull(result);
- assertEquals(1, result.size());
- assertEquals(JsonFormat.ID, result.get(0).getAppId());
- }
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ assertEquals(JsonFormat.ID, result.get(0).getAppId());
+ }
}
diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java
index e355aa937..537f4db13 100644
--- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java
+++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/SourcesManagementTest.java
@@ -23,6 +23,7 @@ import org.apache.streampipes.model.connect.adapter.AdapterStreamDescription;
import org.apache.streampipes.model.connect.adapter.SpecificAdapterStreamDescription;
import org.apache.streampipes.model.schema.EventPropertyPrimitive;
import org.apache.streampipes.model.schema.EventSchema;
+
import org.junit.Before;
import org.junit.Test;
diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java
index 0c8f8bb87..2983be12a 100644
--- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java
+++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/UnitMasterManagementTest.java
@@ -18,11 +18,9 @@
package org.apache.streampipes.connect.container.master.management;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.when;
+import org.apache.streampipes.connect.api.exception.AdapterException;
+import org.apache.streampipes.model.connect.unit.UnitDescription;
+import org.apache.streampipes.units.UnitProvider;
import com.github.jqudt.Unit;
import com.github.jqudt.onto.UnitFactory;
@@ -33,94 +31,98 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-import org.apache.streampipes.connect.api.exception.AdapterException;
-import org.apache.streampipes.model.connect.unit.UnitDescription;
-import org.apache.streampipes.units.UnitProvider;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ UnitProvider.class, UnitFactory.class })
+@PrepareForTest({UnitProvider.class, UnitFactory.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
public class UnitMasterManagementTest {
- @Test(expected = AdapterException.class)
- public void URLisNull() throws AdapterException {
- UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
- unitMasterManagement.getFittingUnits(getUnitDescription("",null));
- }
-
- @Test(expected = AdapterException.class)
- @Ignore
- public void invalidURL() throws AdapterException {
- UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
- when(unitProvider.getUnit(anyString())).thenThrow(new IllegalStateException());
-
- UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
- unitMasterManagement.getFittingUnits(getUnitDescription("","http://test"));
- }
-
- @Test
- public void getFittingUnitsEmpty() throws Exception {
- UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
- when(unitProvider.getUnit(anyString())).thenReturn(new Unit());
- when(unitProvider.getUnitsByType(any())).thenReturn((new ArrayList<>()));
- Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider);
-
- UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
- String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("",""));
- assertEquals("[]", jsonResult);
- }
-
- @Test
- public void getFittingUnitsUnitsEmpty() throws Exception {
- UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
- when(unitProvider.getUnit(anyString())).thenReturn(new Unit());
-
- List<Unit> unitList = new ArrayList<>(2);
- unitList.add(new Unit());
- unitList.add(new Unit());
-
- when(unitProvider.getUnitsByType(any())).thenReturn((unitList));
- Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider);
-
- UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
- String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("",""));
- assertEquals("[]", jsonResult);
- }
-
- @Test
- public void getFittingUnitsUnits() throws Exception {
- UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
- when(unitProvider.getUnit(anyString())).thenReturn(new Unit());
-
- List<Unit> unitList = new ArrayList<>(2);
- Unit unit = new Unit();
- unit.setLabel("A");
- unit.setResource(new URI("http://A"));
- unitList.add(unit);
- unit = new Unit();
- unit.setLabel("A");
- unit.setResource(new URI("http://A"));
- unitList.add(unit);
- unitList.add(new Unit());
-
- when(unitProvider.getUnitsByType(any())).thenReturn((unitList));
- Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider);
-
- UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
- String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("",""));
- assertEquals("[{\"resource\":\"http://A\",\"label\":\"A\"},{\"resource\":\"http://A\",\"label\":\"A\"}]", jsonResult);
- }
-
-
- private UnitDescription getUnitDescription(String label, String ressource) {
- UnitDescription unitDescription = new UnitDescription();
- unitDescription.setLabel(label);
- unitDescription.setResource(ressource);
- return unitDescription;
- }
+ @Test(expected = AdapterException.class)
+ public void URLisNull() throws AdapterException {
+ UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
+ unitMasterManagement.getFittingUnits(getUnitDescription("", null));
+ }
+
+ @Test(expected = AdapterException.class)
+ @Ignore
+ public void invalidURL() throws AdapterException {
+ UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
+ when(unitProvider.getUnit(anyString())).thenThrow(new IllegalStateException());
+
+ UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
+ unitMasterManagement.getFittingUnits(getUnitDescription("", "http://test"));
+ }
+
+ @Test
+ public void getFittingUnitsEmpty() throws Exception {
+ UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
+ when(unitProvider.getUnit(anyString())).thenReturn(new Unit());
+ when(unitProvider.getUnitsByType(any())).thenReturn((new ArrayList<>()));
+ Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider);
+
+ UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
+ String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("", ""));
+ assertEquals("[]", jsonResult);
+ }
+
+ @Test
+ public void getFittingUnitsUnitsEmpty() throws Exception {
+ UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
+ when(unitProvider.getUnit(anyString())).thenReturn(new Unit());
+
+ List<Unit> unitList = new ArrayList<>(2);
+ unitList.add(new Unit());
+ unitList.add(new Unit());
+
+ when(unitProvider.getUnitsByType(any())).thenReturn((unitList));
+ Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider);
+
+ UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
+ String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("", ""));
+ assertEquals("[]", jsonResult);
+ }
+
+ @Test
+ public void getFittingUnitsUnits() throws Exception {
+ UnitProvider unitProvider = mock(UnitProvider.INSTANCE.getClass());
+ when(unitProvider.getUnit(anyString())).thenReturn(new Unit());
+
+ List<Unit> unitList = new ArrayList<>(2);
+ Unit unit = new Unit();
+ unit.setLabel("A");
+ unit.setResource(new URI("http://A"));
+ unitList.add(unit);
+ unit = new Unit();
+ unit.setLabel("A");
+ unit.setResource(new URI("http://A"));
+ unitList.add(unit);
+ unitList.add(new Unit());
+
+ when(unitProvider.getUnitsByType(any())).thenReturn((unitList));
+ Whitebox.setInternalState(UnitProvider.class, "INSTANCE", unitProvider);
+
+ UnitMasterManagement unitMasterManagement = new UnitMasterManagement();
+ String jsonResult = unitMasterManagement.getFittingUnits(getUnitDescription("", ""));
+ assertEquals("[{\"resource\":\"http://A\",\"label\":\"A\"},{\"resource\":\"http://A\",\"label\":\"A\"}]",
+ jsonResult);
+ }
+
+
+ private UnitDescription getUnitDescription(String label, String ressource) {
+ UnitDescription unitDescription = new UnitDescription();
+ unitDescription.setLabel(label);
+ unitDescription.setResource(ressource);
+ return unitDescription;
+ }
}
diff --git a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java
index 401f8946d..3e747196a 100644
--- a/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java
+++ b/streampipes-connect-container-master/src/test/java/org/apache/streampipes/connect/container/master/management/WorkerRestClientTest.java
@@ -22,6 +22,7 @@ import org.apache.streampipes.connect.api.exception.AdapterException;
import org.apache.streampipes.connect.container.master.util.WorkerPaths;
import org.apache.streampipes.model.connect.adapter.GenericAdapterSetDescription;
import org.apache.streampipes.model.connect.adapter.GenericAdapterStreamDescription;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,106 +31,111 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
-import static org.powermock.api.mockito.PowerMockito.*;
+import static org.powermock.api.mockito.PowerMockito.doNothing;
+import static org.powermock.api.mockito.PowerMockito.doThrow;
+import static org.powermock.api.mockito.PowerMockito.verifyStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ WorkerRestClient.class, WorkerPaths.class })
+@PrepareForTest({WorkerRestClient.class, WorkerPaths.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
public class WorkerRestClientTest {
- /**
- * Notes: In this class I tested how powermock could be used to mok static methods
- * One problem is to mock static methods that return void
- */
+ /**
+ * Notes: In this class I tested how powermock could be used to mok static methods
+ * One problem is to mock static methods that return void
+ */
- @Before
- public void before() {
- PowerMockito.mockStatic(WorkerRestClient.class);
- PowerMockito.mockStatic(WorkerPaths.class);
- }
+ @Before
+ public void before() {
+ PowerMockito.mockStatic(WorkerRestClient.class);
+ PowerMockito.mockStatic(WorkerPaths.class);
+ }
- @Test
- public void stopStreamAdapterSuccess() throws Exception {
+ @Test
+ public void stopStreamAdapterSuccess() throws Exception {
- String expectedUrl = "worker/stream/stop";
- doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString());
- when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod();
- when(WorkerPaths.class, "getStreamStopPath").thenReturn(expectedUrl);
- GenericAdapterStreamDescription description = new GenericAdapterStreamDescription();
- description.setElementId("id1");
+ String expectedUrl = "worker/stream/stop";
+ doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString());
+ when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod();
+ when(WorkerPaths.class, "getStreamStopPath").thenReturn(expectedUrl);
+ GenericAdapterStreamDescription description = new GenericAdapterStreamDescription();
+ description.setElementId("id1");
- WorkerRestClient.stopStreamAdapter("", description);
+ WorkerRestClient.stopStreamAdapter("", description);
- verifyStatic(WorkerRestClient.class, times(1));
- WorkerRestClient.stopAdapter(any(), eq(expectedUrl));
+ verifyStatic(WorkerRestClient.class, times(1));
+ WorkerRestClient.stopAdapter(any(), eq(expectedUrl));
- }
+ }
- @Test(expected = AdapterException.class)
- public void stopStreamAdapterFail() throws Exception {
- doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString());
- when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod();
+ @Test(expected = AdapterException.class)
+ public void stopStreamAdapterFail() throws Exception {
+ doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString());
+ when(WorkerRestClient.class, "stopStreamAdapter", anyString(), any()).thenCallRealMethod();
- GenericAdapterStreamDescription description = new GenericAdapterStreamDescription();
- description.setElementId("id1");
+ GenericAdapterStreamDescription description = new GenericAdapterStreamDescription();
+ description.setElementId("id1");
- WorkerRestClient.stopStreamAdapter("", description);
+ WorkerRestClient.stopStreamAdapter("", description);
- }
+ }
- @Test
- public void invokeSetAdapterSuccess() throws Exception {
+ @Test
+ public void invokeSetAdapterSuccess() throws Exception {
- String expectedUrl = "worker/set/invoke";
- doNothing().when(WorkerRestClient.class, "startAdapter", anyString(), any());
- when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod();
- when(WorkerPaths.class, "getSetInvokePath").thenReturn(expectedUrl);
+ String expectedUrl = "worker/set/invoke";
+ doNothing().when(WorkerRestClient.class, "startAdapter", anyString(), any());
+ when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod();
+ when(WorkerPaths.class, "getSetInvokePath").thenReturn(expectedUrl);
- GenericAdapterSetDescription description = new GenericAdapterSetDescription();
- description.setElementId("id1");
- WorkerRestClient.invokeSetAdapter("", description);
+ GenericAdapterSetDescription description = new GenericAdapterSetDescription();
+ description.setElementId("id1");
+ WorkerRestClient.invokeSetAdapter("", description);
- verifyStatic(WorkerRestClient.class, times(1));
- WorkerRestClient.startAdapter(eq("worker/set/invoke"), any());
+ verifyStatic(WorkerRestClient.class, times(1));
+ WorkerRestClient.startAdapter(eq("worker/set/invoke"), any());
- }
+ }
- @Test(expected = AdapterException.class)
- public void invokeSetAdapterFail() throws Exception {
- doThrow(new AdapterException()).when(WorkerRestClient.class, "startAdapter", anyString(), any());
- when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod();
+ @Test(expected = AdapterException.class)
+ public void invokeSetAdapterFail() throws Exception {
+ doThrow(new AdapterException()).when(WorkerRestClient.class, "startAdapter", anyString(), any());
+ when(WorkerRestClient.class, "invokeSetAdapter", anyString(), any()).thenCallRealMethod();
- WorkerRestClient.invokeSetAdapter("", null);
- }
+ WorkerRestClient.invokeSetAdapter("", null);
+ }
- @Test
- public void stopSetAdapterSuccess() throws Exception {
+ @Test
+ public void stopSetAdapterSuccess() throws Exception {
- String expectedUrl = "worker/set/stop";
- doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString());
- when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod();
- when(WorkerPaths.class, "getSetStopPath").thenReturn(expectedUrl);
+ String expectedUrl = "worker/set/stop";
+ doNothing().when(WorkerRestClient.class, "stopAdapter", any(), anyString());
+ when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod();
+ when(WorkerPaths.class, "getSetStopPath").thenReturn(expectedUrl);
- GenericAdapterSetDescription description = new GenericAdapterSetDescription();
- description.setElementId("id1");
- WorkerRestClient.stopSetAdapter("", description);
+ GenericAdapterSetDescription description = new GenericAdapterSetDescription();
+ description.setElementId("id1");
+ WorkerRestClient.stopSetAdapter("", description);
- verifyStatic(WorkerRestClient.class, times(1));
- WorkerRestClient.stopAdapter(any(), eq(expectedUrl));
+ verifyStatic(WorkerRestClient.class, times(1));
+ WorkerRestClient.stopAdapter(any(), eq(expectedUrl));
- }
+ }
- @Test(expected = AdapterException.class)
- public void stopSetAdapterFail() throws Exception {
- doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString());
- when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod();
+ @Test(expected = AdapterException.class)
+ public void stopSetAdapterFail() throws Exception {
+ doThrow(new AdapterException()).when(WorkerRestClient.class, "stopAdapter", any(), anyString());
+ when(WorkerRestClient.class, "stopSetAdapter", anyString(), any()).thenCallRealMethod();
- GenericAdapterSetDescription description = new GenericAdapterSetDescription();
- description.setElementId("id1");
- WorkerRestClient.stopSetAdapter("", description);
+ GenericAdapterSetDescription description = new GenericAdapterSetDescription();
+ description.setElementId("id1");
+ WorkerRestClient.stopSetAdapter("", description);
- }
+ }
}