You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/01/12 15:24:02 UTC
[incubator-plc4x] branch master updated: Added tests for
(Typed)Request/Repsonses
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push:
new d322d6e Added tests for (Typed)Request/Repsonses
d322d6e is described below
commit d322d6ecdc92c1c454e3dd64b80c3cbd85f80b77
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jan 12 16:23:57 2018 +0100
Added tests for (Typed)Request/Repsonses
---
.../plc4x/java/api/messages/PlcReadRequest.java | 2 +-
.../plc4x/java/api/messages/PlcWriteRequest.java | 4 +
.../messages/specific/TypeSafePlcWriteRequest.java | 14 ++--
.../plc4x/java/api/messages/APIMessageTests.java | 1 +
.../java/api/messages/PlcReadRequestTest.java | 88 ++++++++++++++++++++++
.../java/api/messages/PlcReadResponseTest.java | 45 +++++++++++
.../plc4x/java/api/messages/PlcRequestTest.java | 86 +++++++++++++++++++++
.../plc4x/java/api/messages/PlcResponseTest.java | 87 +++++++++++++++++++++
.../java/api/messages/PlcWriteRequestTest.java | 86 +++++++++++++++++++++
.../java/api/messages/PlcWriteResponseTest.java | 45 +++++++++++
.../specific/TypeSafePlcReadRequestTest.java | 77 +++++++++++++++++++
.../specific/TypeSafePlcReadResponseTest.java | 67 ++++++++++++++++
.../specific/TypeSafePlcWriteRequestTest.java | 77 +++++++++++++++++++
.../specific/TypeSafePlcWriteResponseTest.java | 62 +++++++++++++++
14 files changed, 735 insertions(+), 6 deletions(-)
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
index 3168e5b..2aa4f72 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
@@ -30,7 +30,7 @@ public class PlcReadRequest extends PlcRequest<ReadRequestItem<?>> {
}
public PlcReadRequest(ReadRequestItem<?> requestItem) {
- requestItems.add(requestItem);
+ addItem(requestItem);
}
public PlcReadRequest(Class<?> dataType, Address address) {
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
index ce23dc9..816e08d 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
@@ -30,6 +30,10 @@ public class PlcWriteRequest extends PlcRequest<WriteRequestItem<?>> {
public PlcWriteRequest() {
}
+ public PlcWriteRequest(WriteRequestItem<?> requestItem) {
+ addItem(requestItem);
+ }
+
@SafeVarargs
public <T> PlcWriteRequest(Class<T> dataType, Address address, T... values) {
addItem(new WriteRequestItem<>(dataType, address, values));
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
index f8be231..c5efce0 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
@@ -28,10 +28,10 @@ import java.util.Optional;
public class TypeSafePlcWriteRequest<T> extends PlcWriteRequest {
- private final Class<T> datatype;
+ private final Class<T> dataType;
- public TypeSafePlcWriteRequest(Class<T> type) {
- this.datatype = type;
+ public TypeSafePlcWriteRequest(Class<T> dataType) {
+ this.dataType = dataType;
}
public TypeSafePlcWriteRequest(Class<T> dataType, PlcWriteRequest plcWriteRequest) {
@@ -59,8 +59,8 @@ public class TypeSafePlcWriteRequest<T> extends PlcWriteRequest {
@Override
public void addItem(WriteRequestItem<?> writeRequestItem) {
Objects.requireNonNull(writeRequestItem);
- if (writeRequestItem.getDatatype() != datatype) {
- throw new IllegalArgumentException("Incompatible datatype " + writeRequestItem.getDatatype());
+ if (writeRequestItem.getDatatype() != dataType) {
+ throw new IllegalArgumentException("Incompatible dataType " + writeRequestItem.getDatatype());
}
super.addItem(writeRequestItem);
}
@@ -75,4 +75,8 @@ public class TypeSafePlcWriteRequest<T> extends PlcWriteRequest {
public Optional<WriteRequestItem<T>> getRequestItem() {
return (Optional<WriteRequestItem<T>>) super.getRequestItem();
}
+
+ public Class<T> getDataType() {
+ return dataType;
+ }
}
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/APIMessageTests.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/APIMessageTests.java
index a0311e4..fdb3b27 100644
--- a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/APIMessageTests.java
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/APIMessageTests.java
@@ -317,6 +317,7 @@ class APIMessageTests {
ReadResponseItem<Byte> readResponseItem = new ReadResponseItem<>(readRequestItem, ResponseCode.OK, Collections.singletonList((byte) 0x0));
ReadResponseItem<Byte> byteReadResponseItem = readRequestItem.getResponseItem().get(10, TimeUnit.MILLISECONDS);
assertEquals(readResponseItem, byteReadResponseItem);
+ successLatch.await(10, TimeUnit.SECONDS);
assertEquals(0, successLatch.getCount());
assertEquals(10, failLatch.getCount());
}
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadRequestTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadRequestTest.java
new file mode 100644
index 0000000..0b2fe70
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadRequestTest.java
@@ -0,0 +1,88 @@
+/*
+ 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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+class PlcReadRequestTest {
+
+ @Test
+ void constuctor() {
+ new PlcReadRequest();
+ new PlcReadRequest(new ReadRequestItem<>(String.class, null));
+ new PlcReadRequest(String.class, null);
+ new PlcReadRequest(String.class, null, 13);
+ new PlcReadRequest(Collections.singletonList(new ReadRequestItem<>(String.class, null)));
+ }
+
+ @Test
+ void builder() {
+ { // empty
+ Assertions.assertThrows(IllegalStateException.class, () -> PlcReadRequest.builder().build());
+ }
+ { // one item
+ PlcReadRequest.builder()
+ .addItem(String.class, null)
+ .build();
+ }
+ { // one item sized
+ PlcReadRequest.builder()
+ .addItem(String.class, null, 13)
+ .build();
+ }
+ { // one item prebuild
+ PlcReadRequest.builder()
+ .addItem(new ReadRequestItem<>(String.class, null))
+ .build();
+ }
+ { // two different item
+ PlcReadRequest.builder()
+ .addItem(String.class, null)
+ .addItem(Byte.class, null)
+ .build();
+ }
+ { // two different item typeSafe
+ Assertions.assertThrows(IllegalStateException.class, () -> {
+ PlcReadRequest.builder()
+ .addItem(String.class, null)
+ .addItem(Byte.class, null)
+ .build(String.class);
+ });
+ }
+ { // two different item typeSafe
+ Assertions.assertThrows(ClassCastException.class, () -> {
+ PlcReadRequest.builder()
+ .addItem(String.class, null)
+ .addItem(Byte.class, null)
+ .build(Byte.class);
+ });
+ }
+ { // two equal item typeSafe
+ PlcReadRequest.builder()
+ .addItem(Byte.class, null)
+ .addItem(Byte.class, null)
+ .build(Byte.class);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadResponseTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadResponseTest.java
new file mode 100644
index 0000000..55761df
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadResponseTest.java
@@ -0,0 +1,45 @@
+/*
+ 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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
+import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+class PlcReadResponseTest {
+
+ @Test
+ void constuctor() {
+ new PlcReadResponse(mock(PlcReadRequest.class), mock(ReadResponseItem.class));
+ new PlcReadResponse(mock(PlcReadRequest.class), (List) Collections.singletonList(mock(ReadResponseItem.class)));
+ }
+
+ @Test
+ void getValue() {
+ new PlcReadResponse(mock(PlcReadRequest.class), (List) Collections.singletonList(mock(ReadResponseItem.class, RETURNS_DEEP_STUBS)))
+ .getValue(mock(ReadRequestItem.class));
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcRequestTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcRequestTest.java
new file mode 100644
index 0000000..a1714b3
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcRequestTest.java
@@ -0,0 +1,86 @@
+/*
+ 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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.messages.items.RequestItem;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static org.mockito.Mockito.mock;
+
+class PlcRequestTest {
+
+ private List<RequestItem> requestItems;
+
+ private PlcRequest SUT;
+
+ @BeforeEach
+ void setUp() {
+ requestItems = new ArrayList<>();
+ SUT = new PlcRequest<RequestItem>(requestItems) {
+ };
+ }
+
+ @Test
+ void addItem() {
+ SUT.addItem(mock(RequestItem.class));
+ }
+
+ @Test
+ void getRequestItems() {
+ Assertions.assertEquals(0, SUT.getRequestItems().size());
+ }
+
+ @Test
+ void getRequestItem() {
+ Assertions.assertEquals(Optional.empty(), SUT.getRequestItem());
+ requestItems.add(mock(RequestItem.class));
+ Assertions.assertTrue(SUT.getRequestItem().isPresent());
+ requestItems.add(mock(RequestItem.class));
+ Assertions.assertThrows(IllegalStateException.class, () -> SUT.getRequestItem());
+ }
+
+ @Test
+ void setRequestItem() {
+ SUT.setRequestItem(mock(RequestItem.class));
+ requestItems.add(mock(RequestItem.class));
+ Assertions.assertThrows(IllegalStateException.class, () -> SUT.setRequestItem(mock(RequestItem.class)));
+ }
+
+ @Test
+ void getNumberOfItems() {
+ Assertions.assertEquals(0, SUT.getNumberOfItems());
+ }
+
+ @Test
+ void isMultiValue() {
+ Assertions.assertFalse(SUT.isMultiValue());
+ }
+
+ @Test
+ void isEmpty() {
+ Assertions.assertTrue(SUT.isEmpty());
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcResponseTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcResponseTest.java
new file mode 100644
index 0000000..220df87
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcResponseTest.java
@@ -0,0 +1,87 @@
+/*
+ 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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.messages.items.RequestItem;
+import org.apache.plc4x.java.api.messages.items.ResponseItem;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static org.mockito.Mockito.mock;
+
+class PlcResponseTest {
+
+ private List<ResponseItem> responseItems;
+
+ private PlcResponse SUT;
+
+ @BeforeEach
+ void setUp() {
+ responseItems = new ArrayList<>();
+ SUT = new PlcResponse<PlcRequest, ResponseItem, RequestItem>(mock(PlcRequest.class), responseItems) {
+ };
+ }
+
+ @Test
+ void getRequest() {
+ Assertions.assertNotNull(SUT.getRequest());
+ }
+
+ @Test
+ void getResponseItems() {
+ Assertions.assertEquals(0, SUT.getResponseItems().size());
+ }
+
+ @Test
+ void getResponseItem() {
+ Assertions.assertEquals(Optional.empty(), SUT.getResponseItem());
+ responseItems.add(mock(ResponseItem.class));
+ Assertions.assertTrue(SUT.getResponseItem().isPresent());
+ responseItems.add(mock(ResponseItem.class));
+ Assertions.assertThrows(IllegalStateException.class, () -> {
+ SUT.getResponseItem();
+ });
+ }
+
+ @Test
+ void getNumberOfItems() {
+ Assertions.assertEquals(0, SUT.getNumberOfItems());
+ }
+
+ @Test
+ void isMultiValue() {
+ Assertions.assertFalse(SUT.isMultiValue());
+ }
+
+ @Test
+ void isEmpty() {
+ Assertions.assertTrue(SUT.isEmpty());
+ }
+
+ @Test
+ void getValue() {
+ Assertions.assertEquals(Optional.empty(), SUT.getValue(null));
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteRequestTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteRequestTest.java
new file mode 100644
index 0000000..3dbf5c2
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteRequestTest.java
@@ -0,0 +1,86 @@
+/*
+ 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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+class PlcWriteRequestTest {
+ @Test
+ void constuctor() {
+ new PlcWriteRequest();
+ new PlcWriteRequest(new WriteRequestItem<>(String.class, null, ""));
+ new PlcWriteRequest(String.class, null);
+ new PlcWriteRequest(Collections.singletonList(new WriteRequestItem<>(String.class, null)));
+ }
+
+ @Test
+ void builder() {
+ { // empty
+ Assertions.assertThrows(IllegalStateException.class, () -> PlcWriteRequest.builder().build());
+ }
+ { // one item implicit type
+ PlcWriteRequest.builder()
+ .addItem(null, "")
+ .build();
+ }
+ { // one item
+ PlcWriteRequest.builder()
+ .addItem(String.class, null)
+ .build();
+ }
+ { // one item prebuild
+ PlcWriteRequest.builder()
+ .addItem(new WriteRequestItem<>(String.class, null))
+ .build();
+ }
+ { // two different item
+ PlcWriteRequest.builder()
+ .addItem(String.class, null)
+ .addItem(Byte.class, null)
+ .build();
+ }
+ { // two different item typeSafe
+ Assertions.assertThrows(IllegalStateException.class, () -> {
+ PlcWriteRequest.builder()
+ .addItem(String.class, null)
+ .addItem(Byte.class, null)
+ .build(String.class);
+ });
+ }
+ { // two different item typeSafe
+ Assertions.assertThrows(ClassCastException.class, () -> {
+ PlcWriteRequest.builder()
+ .addItem(String.class, null)
+ .addItem(Byte.class, null)
+ .build(Byte.class);
+ });
+ }
+ { // two equal item typeSafe
+ PlcWriteRequest.builder()
+ .addItem(Byte.class, null)
+ .addItem(Byte.class, null)
+ .build(Byte.class);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteResponseTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteResponseTest.java
new file mode 100644
index 0000000..51e3bf5
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteResponseTest.java
@@ -0,0 +1,45 @@
+/*
+ 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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
+import org.apache.plc4x.java.api.messages.items.WriteResponseItem;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+class PlcWriteResponseTest {
+
+ @Test
+ void constuctor() {
+ new PlcWriteResponse(mock(PlcWriteRequest.class), mock(WriteResponseItem.class));
+ new PlcWriteResponse(mock(PlcWriteRequest.class), (List) Collections.singletonList(mock(WriteResponseItem.class)));
+ }
+
+ @Test
+ void getValue() {
+ new PlcWriteResponse(mock(PlcWriteRequest.class), (List) Collections.singletonList(mock(WriteResponseItem.class, RETURNS_DEEP_STUBS)))
+ .getValue(mock(WriteRequestItem.class));
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequestTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequestTest.java
new file mode 100644
index 0000000..294b609
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequestTest.java
@@ -0,0 +1,77 @@
+/*
+ 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.plc4x.java.api.messages.specific;
+
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
+import org.apache.plc4x.java.api.model.Address;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class TypeSafePlcReadRequestTest {
+
+ ReadRequestItem<String> readRequestItemString;
+
+ @BeforeEach
+ void setUp() {
+ readRequestItemString = new ReadRequestItem<>(String.class, null);
+ }
+
+ @Test
+ void constuctor() {
+ new TypeSafePlcReadRequest<>(String.class);
+ new TypeSafePlcReadRequest<>(String.class, mock(PlcReadRequest.class));
+ PlcReadRequest request = mock(PlcReadRequest.class);
+ when(request.getRequestItems()).thenReturn(Collections.singletonList(readRequestItemString));
+ new TypeSafePlcReadRequest<>(String.class, request);
+ new TypeSafePlcReadRequest<>(String.class, mock(Address.class));
+ new TypeSafePlcReadRequest<>(String.class, mock(Address.class), 3);
+ new TypeSafePlcReadRequest<>(String.class, readRequestItemString);
+ Assertions.assertThrows(IllegalArgumentException.class, () -> {
+ new TypeSafePlcReadRequest<>(Byte.class, request);
+ });
+ }
+
+ @Test
+ void addItem() {
+ new TypeSafePlcReadRequest<>(String.class).addItem(readRequestItemString);
+ }
+
+ @Test
+ void getCheckedReadRequestItems() {
+ new TypeSafePlcReadRequest<>(String.class).getCheckedReadRequestItems();
+ }
+
+ @Test
+ void getRequestItem() {
+ new TypeSafePlcReadRequest<>(String.class).getRequestItem();
+ }
+
+ @Test
+ void getDataType() {
+ Assertions.assertEquals(String.class, new TypeSafePlcReadRequest<>(String.class).getDataType());
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponseTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponseTest.java
new file mode 100644
index 0000000..a701d20
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponseTest.java
@@ -0,0 +1,67 @@
+/*
+ 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.plc4x.java.api.messages.specific;
+
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
+import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class TypeSafePlcReadResponseTest {
+
+ ReadResponseItem<String> readResponseItemString;
+
+ @BeforeEach
+ void setUp() {
+ readResponseItemString = new ReadResponseItem<>(mock(ReadRequestItem.class), null, Collections.emptyList());
+ }
+
+ @Test
+ void constuctor() {
+ new TypeSafePlcReadResponse<>(mock(PlcReadResponse.class));
+ PlcReadResponse response = mock(PlcReadResponse.class);
+ when(response.getResponseItems()).thenReturn((List) Collections.singletonList(readResponseItemString));
+ new TypeSafePlcReadResponse<>(response);
+ new TypeSafePlcReadResponse<>(mock(TypeSafePlcReadRequest.class), readResponseItemString);
+ new TypeSafePlcReadResponse<>(mock(TypeSafePlcReadRequest.class), Collections.singletonList(readResponseItemString));
+ }
+
+ @Test
+ void getRequest() {
+ new TypeSafePlcReadResponse<>(mock(PlcReadResponse.class)).getRequest();
+ }
+
+ @Test
+ void getResponseItems() {
+ new TypeSafePlcReadResponse<>(mock(PlcReadResponse.class)).getResponseItems();
+ }
+
+ @Test
+ void getResponseItem() {
+ new TypeSafePlcReadResponse<>(mock(PlcReadResponse.class)).getResponseItem();
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequestTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequestTest.java
new file mode 100644
index 0000000..decd8b6
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequestTest.java
@@ -0,0 +1,77 @@
+/*
+ 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.plc4x.java.api.messages.specific;
+
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
+import org.apache.plc4x.java.api.model.Address;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class TypeSafePlcWriteRequestTest {
+
+ WriteRequestItem<String> writeRequestItemString;
+
+ @BeforeEach
+ void setUp() {
+ writeRequestItemString = new WriteRequestItem<>(String.class, null);
+ }
+
+ @Test
+ void constuctor() {
+ new TypeSafePlcWriteRequest<>(String.class);
+ new TypeSafePlcWriteRequest<>(String.class, mock(PlcWriteRequest.class));
+ PlcWriteRequest request = mock(PlcWriteRequest.class);
+ when(request.getRequestItems()).thenReturn(Collections.singletonList(writeRequestItemString));
+ new TypeSafePlcWriteRequest<>(String.class, request);
+ new TypeSafePlcWriteRequest<>(String.class, mock(Address.class));
+ new TypeSafePlcWriteRequest<>(String.class, mock(Address.class), "");
+ new TypeSafePlcWriteRequest<>(String.class, writeRequestItemString);
+ Assertions.assertThrows(IllegalArgumentException.class, () -> {
+ new TypeSafePlcWriteRequest<>(Byte.class, request);
+ });
+ }
+
+ @Test
+ void addItem() {
+ new TypeSafePlcWriteRequest<>(String.class).addItem(writeRequestItemString);
+ }
+
+ @Test
+ void getCheckedWriteRequestItems() {
+ new TypeSafePlcWriteRequest<>(String.class).getCheckedRequestItems();
+ }
+
+ @Test
+ void getRequestItem() {
+ new TypeSafePlcWriteRequest<>(String.class).getRequestItem();
+ }
+
+ @Test
+ void getDataType() {
+ Assertions.assertEquals(String.class, new TypeSafePlcWriteRequest<>(String.class).getDataType());
+ }
+
+}
\ No newline at end of file
diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponseTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponseTest.java
new file mode 100644
index 0000000..c7575d6
--- /dev/null
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponseTest.java
@@ -0,0 +1,62 @@
+/*
+ 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.plc4x.java.api.messages.specific;
+
+import org.apache.plc4x.java.api.messages.PlcWriteResponse;
+import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
+import org.apache.plc4x.java.api.messages.items.WriteResponseItem;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.mock;
+
+class TypeSafePlcWriteResponseTest {
+ WriteResponseItem<String> writeResponseItemString;
+
+ @BeforeEach
+ void setUp() {
+ writeResponseItemString = new WriteResponseItem<>(mock(WriteRequestItem.class), null);
+ }
+
+ @Test
+ void constuctor() {
+ new TypeSafePlcWriteResponse<>(mock(PlcWriteResponse.class));
+ new TypeSafePlcWriteResponse<>(mock(TypeSafePlcWriteRequest.class), writeResponseItemString);
+ new TypeSafePlcWriteResponse<>(mock(TypeSafePlcWriteRequest.class), Collections.singletonList(writeResponseItemString));
+ }
+
+ @Test
+ void getRequest() {
+ new TypeSafePlcWriteResponse<>(mock(PlcWriteResponse.class)).getRequest();
+ }
+
+ @Test
+ void getResponseItems() {
+ new TypeSafePlcWriteResponse<>(mock(PlcWriteResponse.class)).getResponseItems();
+ }
+
+ @Test
+ void getResponseItem() {
+ new TypeSafePlcWriteResponse<>(mock(PlcWriteResponse.class)).getResponseItem();
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
['"commits@plc4x.apache.org" <co...@plc4x.apache.org>'].