Skip to content

Commit

Permalink
validate target for tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
SrdjanStevanetic committed Apr 29, 2024
1 parent 3c2c603 commit 39afa21
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public String get_TAG_STANDARD_TEST_VALUE_TARGET(String itemDataEndpoint) {
public static final String SEMANTICTAG_ENTITY = "/semantictag/semantictag_entity.json";
public static final String SEMANTICTAG_AGENT_ENTITY = "/semantictag/semantictag_agent_entity.json";
public static final String SEMANTICTAG_VCARD_ADDRESS = "/semantictag/vcard_address.json";
public static final String SEMANTICTAG_WRONG_MISSING_SCOPE = "/semantictag/wrong/web_resource_missing_scope.json";
public static final String TAG_CANONICAL = "/tag/canonical.json";
public static final String TAG_VIA_STRING = "/tag/via_string.json";
public static final String TAG_VIA_ARRAY = "/tag/via_array.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ void createWrongTag() throws Exception {
assertEquals(response.getStatusCode().value(), HttpStatus.BAD_REQUEST.value());
}

@Test
void createSemanticTagWithMissingScope() throws Exception {
String requestBody = AnnotationTestUtils.getJsonStringInput(SEMANTICTAG_WRONG_MISSING_SCOPE);
ResponseEntity<String> response = storeTestAnnotationByType(true, requestBody, WebAnnotationFields.TAG, null);
assertEquals(response.getStatusCode().value(), HttpStatus.BAD_REQUEST.value());
}

@Test
void createTagWithoutBody() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "Annotation",
"motivation": "tagging",
"body": "http://sws.geonames.org/2988507/",
"target": {
"source": "http://comhaltasarchive.ie/tracks/12535"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ protected void validateTag(Annotation webAnnotation)
} else {
validateTagWithValue(body);
}

validateTargetFields(webAnnotation.getTarget());
}

protected void validateLinking(Annotation webAnnotation)
Expand Down Expand Up @@ -800,7 +802,7 @@ private void validateTargetFields(List<Target> targets) throws PropertyValidatio
}

private void validateTargetSpecificResource(Target target) throws PropertyValidationException {
// source must both be present in the target, and beside it (scope or selector) as well
// source must be present in the target, and beside it (scope or selector) as well
if (target.getSource() == null) {
throw new PropertyValidationException(I18nConstantsAnnotation.MESSAGE_MISSING_MANDATORY_FIELD,
I18nConstantsAnnotation.MESSAGE_MISSING_MANDATORY_FIELD,
Expand Down

0 comments on commit 39afa21

Please sign in to comment.