Skip to content

Commit

Permalink
improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacoby committed Oct 17, 2024
1 parent 3273ee6 commit bfe5534
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private void assertValueProviderHeaders(


private void assertValueProviderPropertyReadJson(PropertyValue expected, String httpResponseBody, String query, boolean useHttps)
throws AssetConnectionException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException, PersistenceException {
throws AssetConnectionException, ConfigurationInitializationException, ResourceNotFoundException, PersistenceException {
assertValueProviderPropertyJson(
expected.getValue().getDataType(),
RequestMethod.GET,
Expand All @@ -453,7 +453,7 @@ private void assertValueProviderPropertyReadJson(PropertyValue expected, String


private void assertValueProviderPropertyReadJson(PropertyValue expected, String httpResponseBody, String query, HttpAssetConnectionConfig config)
throws AssetConnectionException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException, PersistenceException {
throws AssetConnectionException, ConfigurationInitializationException, ResourceNotFoundException, PersistenceException {
assertValueProviderPropertyJson(
expected.getValue().getDataType(),
RequestMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ public void testReconnect()

@Test
public void testSubscriptionProviderJsonPropertyInvalidMessage()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException,
PersistenceException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException, PersistenceException {
TestLogger logger = TestLoggerFactory.getTestLogger(MultiFormatSubscriptionProvider.class);
String message = "7";
PropertyValue expected = PropertyValue.of(Datatype.INT, message);
Expand All @@ -205,8 +204,7 @@ public void testSubscriptionProviderJsonPropertyInvalidMessage()

@Test
public void testSubscriptionProviderJsonPropertyWithInvalidQuery()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException,
PersistenceException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException, PersistenceException {
TestLogger logger = TestLoggerFactory.getTestLogger(MultiFormatSubscriptionProvider.class);
assertSubscriptionProvider(
MqttSubscriptionProviderConfig.builder()
Expand Down Expand Up @@ -333,7 +331,7 @@ private void assertSubscriptionProvider(String format, String message, String qu


private void assertSubscriptionProvider(MqttSubscriptionProviderConfig config, Runnable publisher, Callable<Boolean> waitCondition, PropertyValue... expected)
throws AssetConnectionException, ValueFormatException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException, PersistenceException {
throws AssetConnectionException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException, PersistenceException {
MqttAssetConnection assetConnection = newConnection(
ArrayUtils.isEmpty(expected)
? null
Expand Down Expand Up @@ -419,7 +417,7 @@ private MqttAssetConnection newConnection(String url,
MqttValueProviderConfig valueProvider,
MqttOperationProviderConfig operationProvider,
MqttSubscriptionProviderConfig subscriptionProvider)
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException, PersistenceException {
throws ConfigurationInitializationException, ResourceNotFoundException, PersistenceException {
MqttAssetConnectionConfig config = MqttAssetConnectionConfig.builder()
.serverUri(url)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private void assertInvokeOperation(
Map<String, PropertyValue> inoutput,
Map<String, PropertyValue> expectedInoutput,
Map<String, PropertyValue> expectedOutput)
throws AssetConnectionException, InterruptedException, ConfigurationInitializationException, ConfigurationException, IOException, ResourceNotFoundException,
throws AssetConnectionException, InterruptedException, ConfigurationException, IOException, ResourceNotFoundException,
PersistenceException {
assertInvokeOperation(server, nodeId, sync, input, inoutput, expectedInoutput, expectedOutput, null, null);
}
Expand All @@ -670,7 +670,7 @@ private void assertInvokeOperation(
Map<String, PropertyValue> expectedOutput,
List<ArgumentMapping> inputMapping,
List<ArgumentMapping> outputMapping)
throws AssetConnectionException, InterruptedException, ConfigurationInitializationException, ConfigurationException, IOException, ResourceNotFoundException,
throws AssetConnectionException, InterruptedException, ConfigurationException, IOException, ResourceNotFoundException,
PersistenceException {
Reference reference = ReferenceHelper.parseReference("(Property)[ID_SHORT]Temperature");
OpcUaAssetConnectionConfig config = OpcUaAssetConnectionConfig.builder()
Expand Down Expand Up @@ -846,7 +846,7 @@ private void assertWriteReadValue(
String nodeId,
PropertyValue expected,
String arrayIndex)
throws AssetConnectionException, InterruptedException, ConfigurationInitializationException, ConfigurationException, IOException, ResourceNotFoundException,
throws AssetConnectionException, ConfigurationException, IOException, ResourceNotFoundException,
PersistenceException {
Reference reference = ReferenceHelper.parseReference("(Property)[ID_SHORT]Temperature");
ServiceContext serviceContext = mock(ServiceContext.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.digitaltwin.aas4j.v3.model.HasSemantics;
import org.eclipse.digitaltwin.aas4j.v3.model.Referable;
Expand Down Expand Up @@ -95,13 +94,13 @@ public static void splitAssetIdsIntoGlobalAndSpecificIds(List<AssetIdentificatio
.filter(x -> GlobalAssetIdentification.class.isAssignableFrom(x.getClass()))
.map(GlobalAssetIdentification.class::cast)
.map(x -> x.getValue())
.collect(Collectors.toList()));
.toList());
specificIds.addAll(assetIds.stream()
.filter(x -> SpecificAssetIdentification.class.isAssignableFrom(x.getClass()))
.map(x -> new DefaultSpecificAssetId.Builder()
.name(((SpecificAssetIdentification) x).getKey())
.value(((SpecificAssetIdentification) x).getValue())
.value(x.getValue())
.build())
.collect(Collectors.toList()));
.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void stop() {
unregisterAllSubmodels();
}
catch (PersistenceException e) {
LOGGER.error(String.format("unregistration could not be completed."));
LOGGER.error("unregistration could not be completed.");
}
if (Objects.nonNull(executor)) {
executor.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ public void run() {

@Test
public void testOperationProvider()
throws ConfigurationInitializationException, ConfigurationException, AssetConnectionException, MessageBusException, EndpointException, ResourceNotFoundException,
PersistenceException {
throws MessageBusException, EndpointException, ResourceNotFoundException, PersistenceException {
final String submodelId = "submodel";
final String operationId = "property";
final String input1Id = "in1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import de.fraunhofer.iosb.ilt.faaast.service.ServiceContext;
import de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig;
import de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationException;
import de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException;
import de.fraunhofer.iosb.ilt.faaast.service.model.InMemoryFile;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.PersistenceException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -49,7 +47,7 @@ public abstract class AbstractFileStorageTest<T extends FileStorage<C>, C extend


@Test
public void saveAndDelete() throws ConfigurationInitializationException, ResourceNotFoundException, ConfigurationException, IOException, PersistenceException {
public void saveAndDelete() throws ResourceNotFoundException, ConfigurationException, PersistenceException {
FileStorageConfig<T> config = getFileStorageConfig();
fileStorage = config.newInstance(CoreConfig.DEFAULT, SERVICE_CONTEXT);
InMemoryFile expected = InMemoryFile.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import de.fraunhofer.iosb.ilt.faaast.service.ServiceContext;
import de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig;
import de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationException;
import de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException;
import de.fraunhofer.iosb.ilt.faaast.service.model.AASFull;
import de.fraunhofer.iosb.ilt.faaast.service.model.IdShortPath;
import de.fraunhofer.iosb.ilt.faaast.service.model.SubmodelElementIdentifier;
Expand Down Expand Up @@ -121,7 +120,7 @@ public void stop() {


@Test
public void withInitialModelFile() throws ConfigurationInitializationException, ResourceNotFoundException, ConfigurationException, PersistenceException {
public void withInitialModelFile() throws ResourceNotFoundException, ConfigurationException, PersistenceException {
PersistenceConfig<T> config = getPersistenceConfig(fullModelFile, null);
persistence = config.newInstance(CoreConfig.DEFAULT, SERVICE_CONTEXT);
persistence.start();
Expand All @@ -136,17 +135,17 @@ public void withInitialModelFile() throws ConfigurationInitializationException,


@Test
public void withInitialModelAndModelFile() throws ConfigurationInitializationException, ResourceNotFoundException, ConfigurationException, PersistenceException {
public void withInitialModelAndModelFile() throws ResourceNotFoundException, ConfigurationException, PersistenceException {
PersistenceConfig<T> config = getPersistenceConfig(minimalModelFile, environment);
Persistence persistence = config.newInstance(CoreConfig.DEFAULT, SERVICE_CONTEXT);
persistence.start();
Persistence tempPersistence = config.newInstance(CoreConfig.DEFAULT, SERVICE_CONTEXT);
tempPersistence.start();
String aasId = "https://acplt.org/Test_AssetAdministrationShell_Mandatory";
AssetAdministrationShell expected = environment.getAssetAdministrationShells().stream()
.filter(x -> x.getId().equals(aasId))
.findFirst().get();
AssetAdministrationShell actual = persistence.getAssetAdministrationShell(aasId, QueryModifier.DEFAULT);
AssetAdministrationShell actual = tempPersistence.getAssetAdministrationShell(aasId, QueryModifier.DEFAULT);
Assert.assertEquals(expected, actual);
persistence.stop();
tempPersistence.stop();
}


Expand Down Expand Up @@ -598,7 +597,7 @@ public void putSubmodelElementNewInSubmodel() throws ResourceNotFoundException,


@Test
public void putSubmodelElementChangeInSubmodel() throws ResourceNotFoundException, PersistenceException, ResourceNotAContainerElementException, ResourceAlreadyExistsException {
public void putSubmodelElementChangeInSubmodel() throws ResourceNotFoundException, PersistenceException {
String submodelId = "https://acplt.org/Test_Submodel_Mandatory";
Submodel submodel = environment.getSubmodels().stream()
.filter(x -> x.getId().equalsIgnoreCase(submodelId)).findFirst().get();
Expand Down Expand Up @@ -673,8 +672,7 @@ public void putSubmodelElementNewInSubmodelElementList()


@Test
public void putSubmodelElementChangeInSubmodelElementCollection()
throws ResourceNotFoundException, PersistenceException, ResourceNotAContainerElementException, ResourceAlreadyExistsException {
public void putSubmodelElementChangeInSubmodelElementCollection() throws ResourceNotFoundException, PersistenceException {
String submodelId = "https://acplt.org/Test_Submodel_Mandatory";
String submodelElementCollectionId = "ExampleSubmodelElementCollection";
SubmodelElement submodelElement = ((SubmodelElementCollection) environment.getSubmodels().stream()
Expand All @@ -701,8 +699,7 @@ public void putSubmodelElementChangeInSubmodelElementCollection()


@Test
public void putSubmodelElementChangeInSubmodelElementList()
throws ResourceNotFoundException, PersistenceException, ResourceNotAContainerElementException, ResourceAlreadyExistsException {
public void putSubmodelElementChangeInSubmodelElementList() throws ResourceNotFoundException, PersistenceException {
Reference reference = ReferenceHelper.parse("(Submodel)https://acplt.org/Test_Submodel, (SubmodelElementList)ExampleSubmodelElementListOrdered, (SubmodelElement)0");
SubmodelElement submodelElement = EnvironmentHelper.resolve(reference, environment, SubmodelElement.class);
SubmodelElement expected = DeepCopyHelper.deepCopy(submodelElement, submodelElement.getClass());
Expand Down
Loading

0 comments on commit bfe5534

Please sign in to comment.