Skip to content

Commit 9f902cd

Browse files
authored
[DXP-1821] Windows fixes (#212)
1 parent 8679a99 commit 9f902cd

File tree

2 files changed

+134
-101
lines changed

2 files changed

+134
-101
lines changed

core/src/test/java/dev/streamx/cli/command/ingestion/stream/StreamCommandTest.java

Lines changed: 133 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
1414
import com.github.tomakehurst.wiremock.client.WireMock;
1515
import com.github.tomakehurst.wiremock.common.Json;
16+
import com.github.tomakehurst.wiremock.matching.ContainsPattern;
17+
import dev.streamx.cli.command.ingestion.AuthorizedProfile;
1618
import dev.streamx.cli.command.ingestion.BaseIngestionCommandTest;
19+
import dev.streamx.cli.command.ingestion.UnauthorizedProfile;
1720
import dev.streamx.clients.ingestion.publisher.FailureResult;
1821
import dev.streamx.clients.ingestion.publisher.IngestionResult;
1922
import dev.streamx.clients.ingestion.publisher.SuccessResult;
23+
import io.quarkus.test.junit.TestProfile;
2024
import io.quarkus.test.junit.main.LaunchResult;
2125
import io.quarkus.test.junit.main.QuarkusMainLauncher;
2226
import io.quarkus.test.junit.main.QuarkusMainTest;
27+
import org.junit.jupiter.api.Nested;
2328
import org.junit.jupiter.api.Test;
2429

2530
@QuarkusMainTest
@@ -30,108 +35,136 @@ class StreamCommandTest extends BaseIngestionCommandTest {
3035
private static final String UNSUPPORTED_CHANNEL = "images";
3136
private static final String KEY = "index.html";
3237

33-
@Test
34-
public void shouldPublishUsingIngestionClient(QuarkusMainLauncher launcher) {
35-
// when
36-
LaunchResult result = launcher.launch("stream",
37-
"--ingestion-url=" + getIngestionUrl(),
38-
CHANNEL,
39-
"target/test-classes/dev/streamx/cli/command/ingestion/stream/valid-json.stream");
40-
41-
// then
42-
expectSuccess(result);
43-
wm.verify(postRequestedFor(urlEqualTo(getPublicationPath(CHANNEL)))
44-
.withRequestBody(matchingJsonPath("action", equalTo("publish")))
45-
.withoutHeader("Authorization"));
46-
}
47-
48-
@Test
49-
public void shouldPublishToUnsupportedChannel(QuarkusMainLauncher launcher) {
50-
// when
51-
LaunchResult result = launcher.launch("stream",
52-
"--ingestion-url=" + getIngestionUrl(),
53-
UNSUPPORTED_CHANNEL,
54-
"target/test-classes/dev/streamx/cli/command/ingestion/stream/valid-json.stream");
55-
56-
// then
57-
expectError(result, "Ingestion REST endpoint known error. "
58-
+ "Code: UNSUPPORTED_CHANNEL. Message: Channel images is unsupported. "
59-
+ "Supported channels: pages");
60-
wm.verify(postRequestedFor(urlEqualTo(getPublicationPath(UNSUPPORTED_CHANNEL)))
61-
.withRequestBody(matchingJsonPath("action", equalTo("publish")))
62-
.withoutHeader("Authorization"));
63-
}
64-
65-
@Test
66-
public void shouldRejectInvalidJson(QuarkusMainLauncher launcher) {
67-
// when
68-
LaunchResult result = launcher.launch("stream",
69-
"--ingestion-url=" + getIngestionUrl(),
70-
CHANNEL,
71-
"target/test-classes/dev/streamx/cli/command/ingestion/stream/invalid-json.stream");
72-
73-
// then
74-
expectError(result, "Payload could not be parsed.\n"
75-
+ "\n"
76-
+ "Supplied payload:\n"
77-
+ "Cannot parse JSON\n"
78-
+ "\n"
79-
+ "Make sure that:\n"
80-
+ " * it's valid JSON,\n"
81-
+ " * object property names are properly single-quoted (') "
82-
+ "or double-quoted (\"),\n"
83-
+ " * strings are properly single-quoted (') or double-quoted (\")\n"
84-
+ "\n"
85-
+ "Details: Unrecognized token 'ad': was expecting "
86-
+ "(JSON String, Number, Array, Object "
87-
+ "or token 'null', 'true' or 'false')\n"
88-
+ " at [Source: REDACTED "
89-
+ "(`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); "
90-
+ "line: 1, column: 14]");
91-
}
92-
93-
@Test
94-
public void shouldRejectIllegalJson(QuarkusMainLauncher launcher) {
95-
// when
96-
LaunchResult result = launcher.launch("stream",
97-
"--ingestion-url=" + getIngestionUrl(),
98-
CHANNEL,
99-
"target/test-classes/dev/streamx/cli/command/ingestion/stream/illegal-json.stream");
100-
101-
// then
102-
expectError(result, "Error performing stream publication using "
103-
+ "'target/test-classes/dev/streamx/cli/command/ingestion/"
104-
+ "stream/illegal-json.stream' file.\n"
105-
+ "\n"
106-
+ "Details:\n"
107-
+ "Missing or invalid 'action' field\n");
38+
@Nested
39+
@QuarkusMainTest
40+
@TestProfile(UnauthorizedProfile.class)
41+
class UnauthorizedTest {
42+
43+
@Test
44+
public void shouldPublishUsingIngestionClient(QuarkusMainLauncher launcher) {
45+
// when
46+
LaunchResult result = launcher.launch("stream",
47+
"--ingestion-url=" + getIngestionUrl(),
48+
CHANNEL,
49+
"target/test-classes/dev/streamx/cli/command/ingestion/stream/valid-json.stream");
50+
51+
// then
52+
expectSuccess(result);
53+
wm.verify(postRequestedFor(urlEqualTo(getPublicationPath(CHANNEL)))
54+
.withRequestBody(matchingJsonPath("action", equalTo("publish")))
55+
.withoutHeader("Authorization"));
56+
}
57+
58+
@Test
59+
public void shouldPublishToUnsupportedChannel(QuarkusMainLauncher launcher) {
60+
// when
61+
LaunchResult result = launcher.launch("stream",
62+
"--ingestion-url=" + getIngestionUrl(),
63+
UNSUPPORTED_CHANNEL,
64+
"target/test-classes/dev/streamx/cli/command/ingestion/stream/valid-json.stream");
65+
66+
// then
67+
expectError(result, "Ingestion REST endpoint known error. "
68+
+ "Code: UNSUPPORTED_CHANNEL. Message: Channel images is unsupported. "
69+
+ "Supported channels: pages");
70+
wm.verify(postRequestedFor(urlEqualTo(getPublicationPath(UNSUPPORTED_CHANNEL)))
71+
.withRequestBody(matchingJsonPath("action", equalTo("publish")))
72+
.withoutHeader("Authorization"));
73+
}
74+
75+
@Test
76+
public void shouldRejectInvalidJson(QuarkusMainLauncher launcher) {
77+
// when
78+
LaunchResult result = launcher.launch("stream",
79+
"--ingestion-url=" + getIngestionUrl(),
80+
CHANNEL,
81+
"target/test-classes/dev/streamx/cli/command/ingestion/stream/invalid-json.stream");
82+
83+
// then
84+
expectError(result, "Payload could not be parsed.\n"
85+
+ "\n"
86+
+ "Supplied payload:\n"
87+
+ "Cannot parse JSON\n"
88+
+ "\n"
89+
+ "Make sure that:\n"
90+
+ " * it's valid JSON,\n"
91+
+ " * object property names are properly single-quoted (') "
92+
+ "or double-quoted (\"),\n"
93+
+ " * strings are properly single-quoted (') or double-quoted (\")\n"
94+
+ "\n"
95+
+ "Details: Unrecognized token 'ad': was expecting "
96+
+ "(JSON String, Number, Array, Object "
97+
+ "or token 'null', 'true' or 'false')\n"
98+
+ " at [Source: REDACTED "
99+
+ "(`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); "
100+
+ "line: 1, column: 14]");
101+
}
102+
103+
@Test
104+
public void shouldRejectIllegalJson(QuarkusMainLauncher launcher) {
105+
// when
106+
LaunchResult result = launcher.launch("stream",
107+
"--ingestion-url=" + getIngestionUrl(),
108+
CHANNEL,
109+
"target/test-classes/dev/streamx/cli/command/ingestion/stream/illegal-json.stream");
110+
111+
// then
112+
expectError(result, "Error performing stream publication using "
113+
+ "'target/test-classes/dev/streamx/cli/command/ingestion/"
114+
+ "stream/illegal-json.stream' file.\n"
115+
+ "\n"
116+
+ "Details:\n"
117+
+ "Missing or invalid 'action' field\n");
118+
}
119+
120+
@Test
121+
public void shouldRejectInvalidJsonSeparator(QuarkusMainLauncher launcher) {
122+
// when
123+
LaunchResult result = launcher.launch("stream",
124+
"--ingestion-url=" + getIngestionUrl(),
125+
CHANNEL,
126+
"target/test-classes/dev/streamx/cli/command/ingestion/stream"
127+
+ "/invalid-separated-json.stream"
128+
);
129+
130+
// then
131+
expectError(result, "Payload could not be parsed.\n"
132+
+ "\n"
133+
+ "Supplied payload:\n"
134+
+ "Cannot parse JSON\n"
135+
+ "\n"
136+
+ "Make sure that:\n"
137+
+ " * it's valid JSON,\n"
138+
+ " * object property names are properly single-quoted (') "
139+
+ "or double-quoted (\"),\n"
140+
+ " * strings are properly single-quoted (') or double-quoted (\")\n"
141+
+ "\n"
142+
+ "Details: Unexpected character (',' (code 44)): expected a value\n"
143+
+ " at [Source: REDACTED ("
144+
+ "`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); "
145+
+ "line: 15, column: 2]");
146+
}
108147
}
109148

110-
@Test
111-
public void shouldRejectInvalidJsonSeparator(QuarkusMainLauncher launcher) {
112-
// when
113-
LaunchResult result = launcher.launch("stream",
114-
"--ingestion-url=" + getIngestionUrl(),
115-
CHANNEL,
116-
"target/test-classes/dev/streamx/cli/command/ingestion/stream/invalid-separated-json.stream"
117-
);
118-
119-
// then
120-
expectError(result, "Payload could not be parsed.\n"
121-
+ "\n"
122-
+ "Supplied payload:\n"
123-
+ "Cannot parse JSON\n"
124-
+ "\n"
125-
+ "Make sure that:\n"
126-
+ " * it's valid JSON,\n"
127-
+ " * object property names are properly single-quoted (') "
128-
+ "or double-quoted (\"),\n"
129-
+ " * strings are properly single-quoted (') or double-quoted (\")\n"
130-
+ "\n"
131-
+ "Details: Unexpected character (',' (code 44)): expected a value\n"
132-
+ " at [Source: REDACTED ("
133-
+ "`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); "
134-
+ "line: 15, column: 2]");
149+
@Nested
150+
@QuarkusMainTest
151+
@TestProfile(AuthorizedProfile.class)
152+
class AuthorizedTest {
153+
154+
@Test
155+
public void shouldPublishAuthorizedUsing(QuarkusMainLauncher launcher) {
156+
// when
157+
LaunchResult result = launcher.launch("stream",
158+
"--ingestion-url=" + getIngestionUrl(),
159+
CHANNEL,
160+
"target/test-classes/dev/streamx/cli/command/ingestion/stream/valid-json.stream");
161+
162+
// then
163+
expectSuccess(result);
164+
wm.verify(postRequestedFor(urlEqualTo(getPublicationPath(CHANNEL)))
165+
.withRequestBody(matchingJsonPath("action", equalTo("publish")))
166+
.withHeader("Authorization", new ContainsPattern(AuthorizedProfile.AUTH_TOKEN)));
167+
}
135168
}
136169

137170
@Override

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
4242
<quarkus.platform.version>3.18.3</quarkus.platform.version>
4343

44-
<streamx.version>1.0.14</streamx.version>
44+
<streamx.version>1.0.16</streamx.version>
4545
<ingestion-client.version>1.1.1</ingestion-client.version>
4646
<streamx-operator.version>0.0.12</streamx-operator.version>
4747
<json-path.version>2.9.0</json-path.version>

0 commit comments

Comments
 (0)