|
62 | 62 | import java.nio.file.Paths;
|
63 | 63 | import java.util.concurrent.ExecutionException;
|
64 | 64 | import java.util.stream.Stream;
|
| 65 | +import org.testcontainers.containers.GenericContainer; |
| 66 | +import org.testcontainers.containers.output.Slf4jLogConsumer; |
| 67 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 68 | +import org.testcontainers.images.builder.ImageFromDockerfile; |
| 69 | +import org.testcontainers.jib.JibImage; |
| 70 | +import org.testcontainers.junit.jupiter.Container; |
| 71 | +import org.testcontainers.junit.jupiter.Testcontainers; |
65 | 72 |
|
66 | 73 | import static java.util.Map.entry;
|
67 | 74 | import static org.assertj.core.api.Assertions.assertThat;
|
68 | 75 | import static org.assertj.core.api.Assertions.fail;
|
69 | 76 |
|
| 77 | +@Testcontainers(disabledWithoutDocker = true) |
70 | 78 | @DisableOnJenkinsFlag
|
71 |
| -@Disabled("This test regularly fails the build, it needs to be generally fixed.") |
72 | 79 | public class OpcuaPlcDriverTest {
|
73 | 80 |
|
74 | 81 | private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaPlcDriverTest.class);
|
75 | 82 |
|
| 83 | + @Container |
| 84 | + public static final GenericContainer milo = new MiloTestContainer() |
| 85 | + //.withCreateContainerCmdModifier(cmd -> cmd.withHostName("test-opcua-server")) |
| 86 | + .withReuse(true); |
| 87 | + |
76 | 88 | // Read only variables of milo example server of version 3.6
|
77 | 89 | private static final String BOOL_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Boolean";
|
78 | 90 | private static final String BYTE_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Byte";
|
@@ -123,50 +135,55 @@ public class OpcuaPlcDriverTest {
|
123 | 135 | //Restricted
|
124 | 136 | public static final String STRING_IDENTIFIER_ONLY_ADMIN_READ_WRITE = "ns=2;s=HelloWorld/OnlyAdminCanRead/String";
|
125 | 137 |
|
126 |
| - // Address of local milo server |
127 |
| - private final String miloLocalAddress = "127.0.0.1:12686/milo"; |
| 138 | + // Address of local milo server, since it comes from test container its hostname and port is not static |
| 139 | + private final String miloLocalAddress = "%s:%d/milo"; |
128 | 140 | //Tcp pattern of OPC UA
|
129 | 141 | private final String opcPattern = "opcua:tcp://";
|
130 | 142 |
|
131 | 143 | private final String paramSectionDivider = "?";
|
132 | 144 | private final String paramDivider = "&";
|
133 | 145 |
|
134 |
| - private final String tcpConnectionAddress = opcPattern + miloLocalAddress; |
135 |
| - |
136 |
| - private final List<String> connectionStringValidSet = List.of(tcpConnectionAddress); |
137 |
| - private final List<String> connectionStringCorruptedSet = List.of(); |
138 |
| - |
139 | 146 | private final String discoveryValidParamTrue = "discovery=true";
|
140 | 147 | private final String discoveryValidParamFalse = "discovery=false";
|
141 | 148 | private final String discoveryCorruptedParamWrongValueNum = "discovery=1";
|
142 | 149 | private final String discoveryCorruptedParamWrongName = "diskovery=false";
|
143 | 150 |
|
| 151 | + private String tcpConnectionAddress; |
| 152 | + private List<String> connectionStringValidSet; |
| 153 | + |
144 | 154 | final List<String> discoveryParamValidSet = List.of(discoveryValidParamTrue, discoveryValidParamFalse);
|
145 | 155 | List<String> discoveryParamCorruptedSet = List.of(discoveryCorruptedParamWrongValueNum, discoveryCorruptedParamWrongName);
|
146 | 156 |
|
147 | 157 | private static TestMiloServer exampleServer;
|
148 | 158 |
|
| 159 | + @BeforeEach |
| 160 | + public void startUp() { |
| 161 | + //System.out.println(milo.getMappedPort(12686)); |
| 162 | + tcpConnectionAddress = String.format(opcPattern + miloLocalAddress, milo.getHost(), milo.getMappedPort(12686)); |
| 163 | + connectionStringValidSet = List.of(tcpConnectionAddress); |
| 164 | + } |
| 165 | + |
149 | 166 | @BeforeAll
|
150 | 167 | public static void setup() throws Exception {
|
151 | 168 | // When switching JDK versions from a newer to an older version,
|
152 | 169 | // this can cause the server to not start correctly.
|
153 | 170 | // Deleting the directory makes sure the key-store is initialized correctly.
|
154 |
| - Path securityBaseDir = Paths.get(System.getProperty("java.io.tmpdir"), "server", "security"); |
155 |
| - try { |
156 |
| - Files.delete(securityBaseDir); |
157 |
| - } catch (Exception e) { |
158 |
| - // Ignore this ... |
159 |
| - } |
160 |
| - |
161 |
| - exampleServer = new TestMiloServer(); |
162 |
| - exampleServer.startup().get(); |
| 171 | +// Path securityBaseDir = Paths.get(System.getProperty("java.io.tmpdir"), "server", "security"); |
| 172 | +// try { |
| 173 | +// Files.delete(securityBaseDir); |
| 174 | +// } catch (Exception e) { |
| 175 | +// // Ignore this ... |
| 176 | +// } |
| 177 | +// |
| 178 | +// exampleServer = new TestMiloServer(); |
| 179 | +// exampleServer.startup().get(); |
163 | 180 | }
|
164 | 181 |
|
165 | 182 | @AfterAll
|
166 | 183 | public static void tearDown() throws Exception {
|
167 |
| - if (exampleServer != null) { |
168 |
| - exampleServer.shutdown().get(); |
169 |
| - } |
| 184 | +// if (exampleServer != null) { |
| 185 | +// exampleServer.shutdown().get(); |
| 186 | +// } |
170 | 187 | }
|
171 | 188 |
|
172 | 189 | @Nested
|
|
0 commit comments