Skip to content

Commit a921dfd

Browse files
authored
Add Fake test metadata object (#66)
* Add FakeTestMetadata * Use FakeTestMetadata objects in tests * Separate FakeTestMetadata.java to three new objects * Make FakePartitionContextMap, FakePropertiesMap and FakeSystemPropertiesMap implement AKV_01 interfaces * Make FakePartitionContextMap, FakePropertiesMap and FakeSystemPropertiesMap non-stubs * Rename fake objects * Don't wrap Fake objects into interface Impl object in tests
1 parent 92c3f8c commit a921dfd

15 files changed

Lines changed: 273 additions & 276 deletions
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Teragrep Neon log format plugin for AKV_01
3+
* Copyright (C) 2025 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/
46+
package com.teragrep.nlf_01.fakes;
47+
48+
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContext;
49+
import java.util.HashMap;
50+
import java.util.Map;
51+
52+
public final class EventPartitionContextFake implements EventPartitionContext {
53+
54+
public Map<String, Object> asMap() {
55+
final Map<String, Object> partitionContextMap = new HashMap<>();
56+
partitionContextMap.put("FullyQualifiedNamespace", "fully-qualified-namespace");
57+
partitionContextMap.put("EventHubName", "event-hub-name");
58+
partitionContextMap.put("PartitionId", "123");
59+
partitionContextMap.put("ConsumerGroup", "consumer-group");
60+
61+
return partitionContextMap;
62+
}
63+
64+
@Override
65+
public boolean isStub() {
66+
return false;
67+
}
68+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Teragrep Neon log format plugin for AKV_01
3+
* Copyright (C) 2025 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/
46+
package com.teragrep.nlf_01.fakes;
47+
48+
import com.teragrep.akv_01.event.metadata.properties.EventProperties;
49+
import java.util.HashMap;
50+
import java.util.Map;
51+
52+
public final class EventPropertiesFake implements EventProperties {
53+
54+
public Map<String, Object> asMap() {
55+
final Map<String, Object> propertiesMap = new HashMap<>();
56+
propertiesMap.put("prop-key", "prop-value");
57+
propertiesMap.put(null, "important-null-value");
58+
propertiesMap.put("important-key", null);
59+
60+
return propertiesMap;
61+
}
62+
63+
@Override
64+
public boolean isStub() {
65+
return false;
66+
}
67+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Teragrep Neon log format plugin for AKV_01
3+
* Copyright (C) 2025 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/
46+
package com.teragrep.nlf_01.fakes;
47+
48+
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemProperties;
49+
import java.util.HashMap;
50+
import java.util.Map;
51+
52+
public final class EventSystemPropertiesFake implements EventSystemProperties {
53+
54+
public Map<String, Object> asMap() {
55+
final Map<String, Object> systemPropertiesMap = new HashMap<>();
56+
systemPropertiesMap.put("PartitionKey", "456");
57+
systemPropertiesMap.put("SequenceNumber", "12345678900");
58+
59+
return systemPropertiesMap;
60+
}
61+
62+
@Override
63+
public boolean isStub() {
64+
return false;
65+
}
66+
}

src/test/java/com/teragrep/nlf_01/types/ADFActivityRunTypeTest.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
import com.teragrep.akv_01.event.metadata.offset.EventOffsetImpl;
5353
import com.teragrep.akv_01.event.metadata.offset.EventOffsetStub;
5454
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContext;
55-
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContextImpl;
5655
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContextStub;
5756
import com.teragrep.akv_01.event.metadata.properties.EventProperties;
58-
import com.teragrep.akv_01.event.metadata.properties.EventPropertiesImpl;
5957
import com.teragrep.akv_01.event.metadata.properties.EventPropertiesStub;
6058
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemProperties;
61-
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemPropertiesImpl;
6259
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemPropertiesStub;
6360
import com.teragrep.akv_01.event.metadata.time.EnqueuedTime;
6461
import com.teragrep.akv_01.event.metadata.time.EnqueuedTimeImpl;
6562
import com.teragrep.akv_01.event.metadata.time.EnqueuedTimeStub;
6663
import com.teragrep.akv_01.plugin.PluginException;
64+
import com.teragrep.nlf_01.fakes.EventPartitionContextFake;
65+
import com.teragrep.nlf_01.fakes.EventPropertiesFake;
66+
import com.teragrep.nlf_01.fakes.EventSystemPropertiesFake;
6767
import com.teragrep.rlo_14.Facility;
6868
import com.teragrep.rlo_14.SDElement;
6969
import com.teragrep.rlo_14.SDParam;
@@ -74,7 +74,6 @@
7474
import java.io.InputStream;
7575
import java.nio.file.Files;
7676
import java.nio.file.Paths;
77-
import java.util.HashMap;
7877
import java.util.Map;
7978
import java.util.Set;
8079
import java.util.stream.Collectors;
@@ -106,23 +105,9 @@ private ParsedEvent testEvent(
106105

107106
@Test
108107
void testIdealCase() {
109-
final Map<String, Object> partitionContextMap = new HashMap<>();
110-
partitionContextMap.put("FullyQualifiedNamespace", "fully-qualified-namespace");
111-
partitionContextMap.put("EventHubName", "event-hub-name");
112-
partitionContextMap.put("PartitionId", "123");
113-
partitionContextMap.put("ConsumerGroup", "consumer-group");
114-
115-
final Map<String, Object> systemPropertiesMap = new HashMap<>();
116-
systemPropertiesMap.put("PartitionKey", "456");
117-
systemPropertiesMap.put("SequenceNumber", "12345678900");
118-
119-
final Map<String, Object> propertiesMap = new HashMap<>();
120-
propertiesMap.put("prop-key", "prop-value");
121-
propertiesMap.put(null, "important-null-value");
122-
propertiesMap.put("important-key", null);
123-
124108
final ParsedEvent parsedEvent = testEvent(
125-
"src/test/resources/adfactivityrun.json", new EventPartitionContextImpl(partitionContextMap), new EventPropertiesImpl(propertiesMap), new EventSystemPropertiesImpl(systemPropertiesMap), new EnqueuedTimeImpl("2010-01-01T00:00:00"), new EventOffsetImpl("0")
109+
"src/test/resources/adfactivityrun.json", new EventPartitionContextFake(), new EventPropertiesFake(),
110+
new EventSystemPropertiesFake(), new EnqueuedTimeImpl("2010-01-01T00:00:00"), new EventOffsetImpl("0")
126111
);
127112

128113
final ADFActivityRunType type = new ADFActivityRunType(parsedEvent, "localhost");

src/test/java/com/teragrep/nlf_01/types/ADFPipelineRunTypeTest.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
import com.teragrep.akv_01.event.metadata.offset.EventOffsetImpl;
5353
import com.teragrep.akv_01.event.metadata.offset.EventOffsetStub;
5454
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContext;
55-
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContextImpl;
5655
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContextStub;
5756
import com.teragrep.akv_01.event.metadata.properties.EventProperties;
58-
import com.teragrep.akv_01.event.metadata.properties.EventPropertiesImpl;
5957
import com.teragrep.akv_01.event.metadata.properties.EventPropertiesStub;
6058
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemProperties;
61-
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemPropertiesImpl;
6259
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemPropertiesStub;
6360
import com.teragrep.akv_01.event.metadata.time.EnqueuedTime;
6461
import com.teragrep.akv_01.event.metadata.time.EnqueuedTimeImpl;
6562
import com.teragrep.akv_01.event.metadata.time.EnqueuedTimeStub;
6663
import com.teragrep.akv_01.plugin.PluginException;
64+
import com.teragrep.nlf_01.fakes.EventPartitionContextFake;
65+
import com.teragrep.nlf_01.fakes.EventPropertiesFake;
66+
import com.teragrep.nlf_01.fakes.EventSystemPropertiesFake;
6767
import com.teragrep.rlo_14.Facility;
6868
import com.teragrep.rlo_14.SDElement;
6969
import com.teragrep.rlo_14.SDParam;
@@ -74,7 +74,6 @@
7474
import java.io.InputStream;
7575
import java.nio.file.Files;
7676
import java.nio.file.Paths;
77-
import java.util.HashMap;
7877
import java.util.Map;
7978
import java.util.Set;
8079
import java.util.stream.Collectors;
@@ -106,23 +105,9 @@ private ParsedEvent testEvent(
106105

107106
@Test
108107
void testIdealCase() {
109-
final Map<String, Object> partitionContextMap = new HashMap<>();
110-
partitionContextMap.put("FullyQualifiedNamespace", "fully-qualified-namespace");
111-
partitionContextMap.put("EventHubName", "event-hub-name");
112-
partitionContextMap.put("PartitionId", "123");
113-
partitionContextMap.put("ConsumerGroup", "consumer-group");
114-
115-
final Map<String, Object> systemPropertiesMap = new HashMap<>();
116-
systemPropertiesMap.put("PartitionKey", "456");
117-
systemPropertiesMap.put("SequenceNumber", "12345678900");
118-
119-
final Map<String, Object> propertiesMap = new HashMap<>();
120-
propertiesMap.put("prop-key", "prop-value");
121-
propertiesMap.put(null, "important-null-value");
122-
propertiesMap.put("important-key", null);
123-
124108
final ParsedEvent parsedEvent = testEvent(
125-
"src/test/resources/adfpipelinerun.json", new EventPartitionContextImpl(partitionContextMap), new EventPropertiesImpl(propertiesMap), new EventSystemPropertiesImpl(systemPropertiesMap), new EnqueuedTimeImpl("2010-01-01T00:00:00"), new EventOffsetImpl("0")
109+
"src/test/resources/adfpipelinerun.json", new EventPartitionContextFake(), new EventPropertiesFake(),
110+
new EventSystemPropertiesFake(), new EnqueuedTimeImpl("2010-01-01T00:00:00"), new EventOffsetImpl("0")
126111
);
127112

128113
final ADFPipelineRunType type = new ADFPipelineRunType(parsedEvent, "localhost");

src/test/java/com/teragrep/nlf_01/types/AppInsightTypeTest.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
import com.teragrep.akv_01.event.metadata.offset.EventOffsetImpl;
5353
import com.teragrep.akv_01.event.metadata.offset.EventOffsetStub;
5454
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContext;
55-
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContextImpl;
5655
import com.teragrep.akv_01.event.metadata.partitionContext.EventPartitionContextStub;
5756
import com.teragrep.akv_01.event.metadata.properties.EventProperties;
58-
import com.teragrep.akv_01.event.metadata.properties.EventPropertiesImpl;
5957
import com.teragrep.akv_01.event.metadata.properties.EventPropertiesStub;
6058
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemProperties;
61-
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemPropertiesImpl;
6259
import com.teragrep.akv_01.event.metadata.systemProperties.EventSystemPropertiesStub;
6360
import com.teragrep.akv_01.event.metadata.time.EnqueuedTime;
6461
import com.teragrep.akv_01.event.metadata.time.EnqueuedTimeImpl;
6562
import com.teragrep.akv_01.event.metadata.time.EnqueuedTimeStub;
6663
import com.teragrep.akv_01.plugin.PluginException;
64+
import com.teragrep.nlf_01.fakes.EventPartitionContextFake;
65+
import com.teragrep.nlf_01.fakes.EventPropertiesFake;
66+
import com.teragrep.nlf_01.fakes.EventSystemPropertiesFake;
6767
import com.teragrep.rlo_14.Facility;
6868
import com.teragrep.rlo_14.SDElement;
6969
import com.teragrep.rlo_14.SDParam;
@@ -72,17 +72,15 @@
7272
import jakarta.json.JsonObject;
7373
import jakarta.json.JsonReader;
7474
import jakarta.json.JsonValue;
75-
import org.junit.jupiter.api.Assertions;
76-
import org.junit.jupiter.api.Test;
77-
7875
import java.io.IOException;
7976
import java.io.InputStream;
8077
import java.nio.file.Files;
8178
import java.nio.file.Paths;
82-
import java.util.HashMap;
8379
import java.util.Map;
8480
import java.util.Set;
8581
import java.util.stream.Collectors;
82+
import org.junit.jupiter.api.Assertions;
83+
import org.junit.jupiter.api.Test;
8684

8785
public final class AppInsightTypeTest {
8886

@@ -111,23 +109,9 @@ private ParsedEvent testEvent(
111109

112110
@Test
113111
void testIdealCase() {
114-
final Map<String, Object> partitionContextMap = new HashMap<>();
115-
partitionContextMap.put("FullyQualifiedNamespace", "fully-qualified-namespace");
116-
partitionContextMap.put("EventHubName", "event-hub-name");
117-
partitionContextMap.put("PartitionId", "123");
118-
partitionContextMap.put("ConsumerGroup", "consumer-group");
119-
120-
final Map<String, Object> systemPropertiesMap = new HashMap<>();
121-
systemPropertiesMap.put("PartitionKey", "456");
122-
systemPropertiesMap.put("SequenceNumber", "12345678900");
123-
124-
final Map<String, Object> propertiesMap = new HashMap<>();
125-
propertiesMap.put("prop-key", "prop-value");
126-
propertiesMap.put(null, "important-null-value");
127-
propertiesMap.put("important-key", null);
128-
129112
final ParsedEvent parsedEvent = testEvent(
130-
"src/test/resources/appinsight_object.json", new EventPartitionContextImpl(partitionContextMap), new EventPropertiesImpl(propertiesMap), new EventSystemPropertiesImpl(systemPropertiesMap), new EnqueuedTimeImpl("2010-01-01T00:00:00"), new EventOffsetImpl("0")
113+
"src/test/resources/appinsight_object.json", new EventPartitionContextFake(), new EventPropertiesFake(),
114+
new EventSystemPropertiesFake(), new EnqueuedTimeImpl("2010-01-01T00:00:00"), new EventOffsetImpl("0")
131115
);
132116

133117
final AppInsightType type = new AppInsightType(parsedEvent, "localhost");

0 commit comments

Comments
 (0)