Skip to content

Commit a8ae48b

Browse files
committed
More HTTP tests
If no LDT template matches, 404 Not Found is only returned from GET and DELETE (POST and PUT succeed) Fixed (?) travis.yml
1 parent 774ab5e commit a8ae48b

10 files changed

Lines changed: 69 additions & 18 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ before_script:
1818
- while ! curl -w "%{http_code}\n" -s -o /dev/null http://localhost:8081 | grep "404" ; do sleep 1 ; done # wait for processor-ct-write to start
1919
- while ! curl -w "%{http_code}\n" -s -o /dev/null http://localhost:8082 | grep "404" ; do sleep 1 ; done # wait for processor-ngt to start
2020
- while ! curl -w "%{http_code}\n" -s -o /dev/null http://localhost:8083 | grep "404" ; do sleep 1 ; done # wait for processor-ngt-write to start
21-
- while ! curl -w "%{http_code}\n" -s http://localhost:8084 | grep "500" ; do sleep 1 ; done # wait for processor-custom to start
22-
- while ! curl -w "%{http_code}\n" -s http://localhost:8085 | grep "500" ; do sleep 1 ; done # wait for processor-custom-write to start
21+
- while ! curl -w "%{http_code}\n" -s -o /dev/null http://localhost:8084 | grep "404" ; do sleep 1 ; done # wait for processor-custom to start
22+
- while ! curl -w "%{http_code}\n" -s -o /dev/null http://localhost:8085 | grep "404" ; do sleep 1 ; done # wait for processor-custom-write to start
2323

2424
script:
2525
- bash ./run.sh # run tests
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
curl -w "%{http_code}\n" -f -s \
4+
-H "Accept: application/n-quads" \
5+
"${BASE_URL}" \
6+
| grep -q "${STATUS_NOT_FOUND}"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
(
4+
curl -w "%{http_code}\n" -f -s \
5+
-X PUT \
6+
-H "Accept: application/n-triples" \
7+
-H "Content-Type: application/n-triples" \
8+
--data-binary @- \
9+
"${BASE_URL_WRITABLE}" <<EOF
10+
<${BASE_URL_WRITABLE}> <http://example.com/default-predicate> "new object PUT" .
11+
EOF
12+
) \
13+
| grep -q "${STATUS_CREATED}"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
curl -w "%{http_code}\n" -f -s \
4+
-H "Accept: application/n-quads" \
5+
"${BASE_URL}" \
6+
| grep -q "${STATUS_NOT_FOUND}"

http-tests/linked-data-templates/custom/POST-non-match-404.sh renamed to http-tests/linked-data-templates/custom/POST-non-match.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ curl -w "%{http_code}\n" -f -s \
44
-X POST \
55
-H "Accept: application/n-quads" \
66
-H "Content-Type: application/n-quads" \
7-
"${BASE_URL}non-match" \
8-
| grep -q "${STATUS_NOT_FOUND}"
7+
"${BASE_URL_WRITABLE}non-match" \
8+
| grep -q "${STATUS_OK}"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
(
4+
curl -w "%{http_code}\n" -f -s \
5+
-X PUT \
6+
-H "Accept: application/n-triples" \
7+
-H "Content-Type: application/n-triples" \
8+
--data-binary @- \
9+
"${BASE_URL_WRITABLE}" <<EOF
10+
<${BASE_URL_WRITABLE}> <http://example.com/default-predicate> "new object PUT" .
11+
EOF
12+
) \
13+
| grep -q "${STATUS_CREATED}"

http-tests/linked-data-templates/custom/PUT-non-match-404.sh renamed to http-tests/linked-data-templates/custom/PUT-non-match.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ curl -w "%{http_code}\n" -f -s \
44
-X PUT \
55
-H "Accept: application/n-quads" \
66
-H "Content-Type: application/n-quads" \
7-
"${BASE_URL}non-match" \
8-
| grep -q "${STATUS_NOT_FOUND}"
7+
"${BASE_URL_WRITABLE}non-match" \
8+
| grep -q "${STATUS_CREATED}"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
curl -w "%{http_code}\n" -f -s \
4+
-H "Accept: application/n-quads" \
5+
"${BASE_URL}" \
6+
| grep -q "${STATUS_NOT_FOUND}"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
(
4+
curl -w "%{http_code}\n" -f -s \
5+
-X PUT \
6+
-H "Accept: application/n-triples" \
7+
-H "Content-Type: application/n-triples" \
8+
--data-binary @- \
9+
"${BASE_URL_WRITABLE}" <<EOF
10+
<${BASE_URL_WRITABLE}> <http://example.com/default-predicate> "new object PUT" .
11+
EOF
12+
) \
13+
| grep -q "${STATUS_CREATED}"

src/main/java/com/atomgraph/server/model/impl/ResourceBase.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ protected ResourceBase(final UriInfo uriInfo, final Request request, final Media
109109
{
110110
super(uriInfo, request, mediaTypes, uri, service);
111111

112-
// if (templateCall == null)
113-
// {
114-
// if (log.isDebugEnabled()) log.debug("Resource {} has not matched any template, returning 404 Not Found", getURI());
115-
// throw new NotFoundException("Resource has not matched any template");
116-
// }
117112
if (application == null) throw new IllegalArgumentException("Application cannot be null");
118113
if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
119114
if (httpHeaders == null) throw new IllegalArgumentException("HttpHeaders cannot be null");
@@ -203,13 +198,7 @@ protected ResourceBase(final UriInfo uriInfo, final Request request, final Media
203198
@Override
204199
public Object getSubResource()
205200
{
206-
if (!getTemplateCall().isPresent())
207-
{
208-
if (log.isDebugEnabled()) log.debug("Resource {} has not matched any ldt:Template, returning 404 Not Found", getURI());
209-
throw new NotFoundException("Resource has not matched any ldt:Template");
210-
}
211-
212-
if (getTemplateCall().get().getTemplate().getLoadClass() != null)
201+
if (getTemplateCall().isPresent() && getTemplateCall().get().getTemplate().getLoadClass() != null)
213202
{
214203
Resource javaClass = getTemplateCall().get().getTemplate().getLoadClass();
215204
if (!javaClass.isURIResource())
@@ -235,6 +224,11 @@ public Object getSubResource()
235224
@Override
236225
public Response get()
237226
{
227+
if (!getTemplateCall().isPresent())
228+
{
229+
if (log.isDebugEnabled()) log.debug("Resource {} has not matched any ldt:Template, returning 404 Not Found", getURI());
230+
throw new NotFoundException("Resource has not matched any ldt:Template");
231+
}
238232
if (getQueryResource() == null) // cannot be validated in constructor in Jersey 2.x: https://github.com/eclipse-ee4j/jersey/issues/4436
239233
{
240234
if (log.isErrorEnabled()) log.error("ldt:query value for template '{}' is missing", getTemplateCall().get().getTemplate());

0 commit comments

Comments
 (0)