Skip to content

Commit

Permalink
version 1.2.6: allow * path (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvd12 authored Jan 6, 2024
1 parent d416b37 commit 0a31c04
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ezyhttp-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>

<artifactId>ezyhttp-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>

<artifactId>ezyhttp-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tvd12.ezyhttp.core.net;

import com.tvd12.ezyfox.util.EzyEntry;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

import com.tvd12.ezyfox.util.EzyEntry;

public final class PathVariables {

private PathVariables() {}
Expand All @@ -23,6 +23,17 @@ public static List<Entry<String, String>> getVariables(
String varName = getVariableName(templatePath);
String varValue = uriPaths[i];
answer.add(EzyEntry.of(varName, varValue));
} else if (templatePath.equals("*")) {
StringBuilder varValue = new StringBuilder();
int lastIndex = uriPaths.length - 1;
for (; i < uriPaths.length; ++i) {
varValue.append(uriPaths[i]);
if (i < lastIndex) {
varValue.append("/");
}
}
answer.add(EzyEntry.of("*", varValue.toString()));
break;
}
}
return answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public String getMatchedURI(String uri) {
child = lastChild.children.get("{}");
}
if (child == null) {
return null;
child = lastChild.children.get("*");
return child == null ? null : child.uri;
}
lastChild = child;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.tvd12.ezyhttp.core.test.net;

import java.util.List;
import java.util.Map.Entry;

import org.testng.annotations.Test;

import com.tvd12.ezyfox.util.EzyMapBuilder;
import com.tvd12.ezyhttp.core.net.PathVariables;
import com.tvd12.test.assertion.Asserts;
import com.tvd12.test.base.BaseTest;
import com.tvd12.test.performance.Performance;
import org.testng.annotations.Test;

import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;

public class PathVariablesTest extends BaseTest {

Expand All @@ -30,4 +31,51 @@ public void isPathVariableTest() {
Asserts.assertFalse(PathVariables.isPathVariable("a"));
Asserts.assertFalse(PathVariables.isPathVariable("a}"));
}

@Test
public void anyPathTest() {
// given
String template = "/market/items/{projectName}/java/docs/*";
String uri = "/market/items/hello/java/docs/world/index.html";

// when
List<Entry<String, String>> actual = PathVariables.getVariables(
template,
uri
);

// then
Asserts.assertEquals(
actual.stream()
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)),
EzyMapBuilder.mapBuilder()
.put("projectName", "hello")
.put("*", "world/index.html")
.build()
);
}

@Test
public void anyPathComplexTest() {
// given
String template = "/versions/{ezyplatformVersion}/java-docs/{moduleName}/*";
String uri = "/versions/0.0.2/java-docs/ezyplatform-web/org/youngmonkeys/ezyplatform/web/package-frame.html";

// when
List<Entry<String, String>> actual = PathVariables.getVariables(
template,
uri
);

// then
Asserts.assertEquals(
actual.stream()
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)),
EzyMapBuilder.mapBuilder()
.put("ezyplatformVersion", "0.0.2")
.put("moduleName", "ezyplatform-web")
.put("*", "org/youngmonkeys/ezyplatform/web/package-frame.html")
.build()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,20 @@ public void getMatchedURIChildNull2() {
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}/{foo}"));
Asserts.assertNull(tree.getMatchedURI("/api/v1/hello/{world}/{foo}/{bar}/unknown"));
}

@Test
public void matchAllTest() {
// given
URITree tree = new URITree();
tree.addURI("/market/items/hello/java/docs/*");

// when
// then
System.out.println(tree);
Asserts.assertNull(tree.getMatchedURI("/market/items/hello/java"));
Asserts.assertNull(tree.getMatchedURI("/market/items/hello/java/docs"));
Asserts.assertNull(tree.getMatchedURI("/market/items/hello/java/docs/"));
Asserts.assertNotNull(tree.getMatchedURI("/market/items/hello/java/docs/index.html"));
Asserts.assertNotNull(tree.getMatchedURI("/market/items/hello/java/docs/com/tvd12/index.html"));
}
}
2 changes: 1 addition & 1 deletion ezyhttp-server-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>

<artifactId>ezyhttp-server-boot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>

<artifactId>ezyhttp-server-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-graphql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>
<artifactId>ezyhttp-server-graphql</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>

<artifactId>ezyhttp-server-jetty</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-management/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>
<artifactId>ezyhttp-server-management</artifactId>
<name>ezyhttp-server-management</name>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-thymeleaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>
<artifactId>ezyhttp-server-thymeleaf</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-tomcat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</parent>

<artifactId>ezyhttp-server-tomcat</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.0.6</version>
</parent>
<artifactId>ezyhttp</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
<packaging>pom</packaging>

<name>ezyhttp</name>
Expand Down

0 comments on commit 0a31c04

Please sign in to comment.