-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2144 Added migration test for OpcUaAdapterMigrationV2
- Loading branch information
Showing
6 changed files
with
317 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...org/apache/streampipes/extensions/connectors/opcua/adapter/OpcUaAdapterMigrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (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 | ||
* | ||
* 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.extensions.connectors.opcua.adapter; | ||
|
||
import org.apache.streampipes.extensions.connectors.opcua.adapter.config.OpcUaAdapterVersionedConfig; | ||
import org.apache.streampipes.extensions.connectors.opcua.migration.OpcUaAdapterMigrationV2; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class OpcUaAdapterMigrationTest { | ||
|
||
private OpcUaAdapterMigrationV2 migrationV2; | ||
|
||
@Before | ||
public void setUp(){ | ||
migrationV2 = new OpcUaAdapterMigrationV2(); | ||
} | ||
|
||
@Test | ||
public void testMigrationV2(){ | ||
var v1 = OpcUaAdapterVersionedConfig.getOpcUaAdapterDescriptionV1(); | ||
var v2 = OpcUaAdapterVersionedConfig.getOpcUaAdapterDescriptionV2(); | ||
|
||
var migrationResult = migrationV2.migrate(v1, null); | ||
|
||
assertTrue(migrationResult.success()); | ||
assertCollectionsEqual(v2.getConfig(), migrationResult.element().getConfig()); | ||
} | ||
|
||
private <T> void assertCollectionsEqual(List<T> list1, List<T> list2) { | ||
assertEquals(list1.size(), list2.size()); | ||
assertTrue(list1.containsAll(list2)); | ||
assertTrue(list2.containsAll(list1)); | ||
} | ||
|
||
} |
151 changes: 151 additions & 0 deletions
151
...e/streampipes/extensions/connectors/opcua/adapter/config/OpcUaAdapterVersionedConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (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 | ||
* | ||
* 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.extensions.connectors.opcua.adapter.config; | ||
|
||
import org.apache.streampipes.extensions.connectors.opcua.adapter.OpcUaAdapter; | ||
import org.apache.streampipes.model.AdapterType; | ||
import org.apache.streampipes.model.connect.adapter.AdapterDescription; | ||
import org.apache.streampipes.sdk.StaticProperties; | ||
import org.apache.streampipes.sdk.builder.adapter.AdapterConfigurationBuilder; | ||
import org.apache.streampipes.sdk.helpers.Alternatives; | ||
import org.apache.streampipes.sdk.helpers.Labels; | ||
import org.apache.streampipes.sdk.helpers.Locales; | ||
import org.apache.streampipes.sdk.utils.Assets; | ||
|
||
import java.util.List; | ||
|
||
import static org.apache.streampipes.extensions.connectors.opcua.adapter.OpcUaAdapter.ID; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.ACCESS_MODE; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.ADAPTER_TYPE; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.AVAILABLE_NODES; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.HOST_PORT; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_HOST; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_HOST_OR_URL; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_SERVER_HOST; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_SERVER_PORT; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_SERVER_URL; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_URL; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.PASSWORD; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.PULLING_INTERVAL; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.PULL_MODE; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.SUBSCRIPTION_MODE; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.UNAUTHENTICATED; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.USERNAME; | ||
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.USERNAME_GROUP; | ||
|
||
public class OpcUaAdapterVersionedConfig { | ||
|
||
public static AdapterDescription getOpcUaAdapterDescriptionV1(){ | ||
var builder = AdapterConfigurationBuilder.create(ID, 1, OpcUaAdapter::new) | ||
.withAssets(Assets.DOCUMENTATION, Assets.ICON) | ||
.withLocales(Locales.EN) | ||
.withCategory(AdapterType.Generic, AdapterType.Manufacturing) | ||
.requiredAlternatives(Labels.withId(ADAPTER_TYPE), | ||
Alternatives.from(Labels.withId(PULL_MODE), | ||
StaticProperties.integerFreeTextProperty( | ||
Labels.withId(PULLING_INTERVAL))), | ||
Alternatives.from(Labels.withId(SUBSCRIPTION_MODE))); | ||
var dependsOn = List.of( | ||
ADAPTER_TYPE.name(), | ||
ACCESS_MODE.name(), | ||
OPC_HOST_OR_URL.name()); | ||
builder | ||
.requiredAlternatives(Labels.withId(ACCESS_MODE), | ||
Alternatives.from(Labels.withId(UNAUTHENTICATED)), | ||
Alternatives.from(Labels.withId(USERNAME_GROUP), | ||
StaticProperties.group( | ||
Labels.withId(USERNAME_GROUP), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(USERNAME)), | ||
StaticProperties.secretValue(Labels.withId(PASSWORD)) | ||
)) | ||
) | ||
.requiredAlternatives(Labels.withId(OPC_HOST_OR_URL), | ||
Alternatives.from( | ||
Labels.withId(OPC_URL), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(OPC_SERVER_URL), "opc.tcp://localhost:4840")) | ||
, | ||
Alternatives.from(Labels.withId(OPC_HOST), | ||
StaticProperties.group( | ||
Labels.withId(HOST_PORT), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(OPC_SERVER_HOST)), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(OPC_SERVER_PORT)) | ||
)) | ||
) | ||
.requiredRuntimeResolvableTreeInput( | ||
Labels.withId(AVAILABLE_NODES.name()), | ||
dependsOn, | ||
true, | ||
true | ||
); | ||
return builder.buildConfiguration().getAdapterDescription(); | ||
} | ||
|
||
public static AdapterDescription getOpcUaAdapterDescriptionV2(){ | ||
var builder = AdapterConfigurationBuilder.create(ID, 2, OpcUaAdapter::new) | ||
.withAssets(Assets.DOCUMENTATION, Assets.ICON) | ||
.withLocales(Locales.EN) | ||
.withCategory(AdapterType.Generic, AdapterType.Manufacturing) | ||
.requiredAlternatives(Labels.withId(ADAPTER_TYPE), | ||
Alternatives.from(Labels.withId(PULL_MODE), | ||
StaticProperties.integerFreeTextProperty( | ||
Labels.withId(PULLING_INTERVAL))), | ||
Alternatives.from(Labels.withId(SUBSCRIPTION_MODE))); | ||
var dependsOn = List.of( | ||
ADAPTER_TYPE.name(), | ||
ACCESS_MODE.name(), | ||
OPC_HOST_OR_URL.name()); | ||
builder | ||
.requiredAlternatives(Labels.withId(ACCESS_MODE), | ||
Alternatives.from(Labels.withId(UNAUTHENTICATED)), | ||
Alternatives.from(Labels.withId(USERNAME_GROUP), | ||
StaticProperties.group( | ||
Labels.withId(USERNAME_GROUP), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(USERNAME)), | ||
StaticProperties.secretValue(Labels.withId(PASSWORD)) | ||
)) | ||
) | ||
.requiredAlternatives(Labels.withId(OPC_HOST_OR_URL), | ||
Alternatives.from( | ||
Labels.withId(OPC_URL), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(OPC_SERVER_URL), "opc.tcp://localhost:4840")) | ||
, | ||
Alternatives.from(Labels.withId(OPC_HOST), | ||
StaticProperties.group( | ||
Labels.withId(HOST_PORT), | ||
StaticProperties.stringFreeTextProperty( | ||
Labels.withId(OPC_SERVER_HOST)), | ||
StaticProperties.integerFreeTextProperty( | ||
Labels.withId(OPC_SERVER_PORT)) | ||
)) | ||
) | ||
.requiredRuntimeResolvableTreeInput( | ||
Labels.withId(AVAILABLE_NODES.name()), | ||
dependsOn, | ||
true, | ||
true | ||
); | ||
return builder.buildConfiguration().getAdapterDescription(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters