urn_perun_vo_attribute_def_def_aup extends VoAttributesModuleAbstract implements VoAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl perunSession, Vo vo, Attribute attribute) throws WrongAttributeValueException { String value = attribute.valueAsString(); if (value == null) return; try { JSONArray array = new JSONArray(value); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); if (!object.has("version")) throw new WrongAttributeValueException(attribute, "AUP is missing key version in JSON."); if (!object.has("date")) throw new WrongAttributeValueException(attribute, "AUP is missing key date in JSON."); if (!object.has("link")) throw new WrongAttributeValueException(attribute, "AUP is missing key link in JSON."); if (!object.has("text")) throw new WrongAttributeValueException(attribute, "AUP is missing key text in JSON."); } } catch (JSONException ex) { throw new WrongAttributeValueException(attribute, "AUP is not valid JSON.", ex); } }  @Override void checkAttributeSyntax(PerunSessionImpl perunSession, Vo vo, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckValueWithMissingVersion() throws Exception { System.out.println("testCheckValueWithMissingVersion()"); attributeToCheck.setValue("[{date: date, link: link, text: text}]"); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckValueWithMissingDate() throws Exception { System.out.println("testCheckValueWithMissingDate()"); attributeToCheck.setValue("[{version: version, link: link, text: text}]"); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckValueWithMissingLink() throws Exception { System.out.println("testCheckValueWithMissingLink()"); attributeToCheck.setValue("[{version: version, date: date, text: text}]"); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckValueWithMissingText() throws Exception { System.out.println("testCheckValueWithMissingText()"); attributeToCheck.setValue("[{version: version, date: date, link: link}]"); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); attributeToCheck.setValue("[{version: version, date: date, link: link, text: text}]"); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }