@Test public void testFind() { String AGENCY_SCHEME = "http: String AGENCY_ONE_VALUE = "One"; SchemeValuePair.mapBehavior(AgencyId.class.getName(), SchemeValueBehavior.ALLOW_ANY); String AGENCY_TWO_VALUE = "Two"; AgencyId agencyIdTwoViaFind = null; try { agencyIdTwoViaFind = AgencyId.find(null, AGENCY_TWO_VALUE); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("AgencyId.find() method threw exception for scheme 'null' and value '" + AGENCY_TWO_VALUE + "' - was AgencyId set to allow any in configuration?"); } AgencyId agencyIdOtherTwoViaFind = null; try { agencyIdOtherTwoViaFind = AgencyId.find(null, AGENCY_TWO_VALUE); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("AgencyId.find() method threw exception for scheme 'null' and value '" + AGENCY_TWO_VALUE + "' - was AgencyId set to allow any in configuration?"); } Assert.assertEquals(agencyIdTwoViaFind, agencyIdOtherTwoViaFind); Assert.assertSame(agencyIdTwoViaFind, agencyIdOtherTwoViaFind); AgencyId agencyIdOneWithSchemeViaFind = null; try { agencyIdOneWithSchemeViaFind = AgencyId.find(AGENCY_SCHEME, AGENCY_ONE_VALUE); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("AgencyId.find() method threw exception for scheme '" + AGENCY_SCHEME + "' and value '" + AGENCY_ONE_VALUE + "' - was AgencyId set to allow any in configuration?"); } AgencyId agencyIdOtherOneWithSchemeViaFind = null; try { agencyIdOtherOneWithSchemeViaFind = AgencyId.find(AGENCY_SCHEME, AGENCY_ONE_VALUE); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("AgencyId.find() method threw exception for scheme '" + AGENCY_SCHEME + "' and value '" + AGENCY_ONE_VALUE + "' - was AgencyId set to allow any in configuration?"); } Assert.assertEquals(agencyIdOneWithSchemeViaFind, agencyIdOtherOneWithSchemeViaFind); Assert.assertSame(agencyIdOneWithSchemeViaFind, agencyIdOtherOneWithSchemeViaFind); String AGENCY_THREE_VALUE = "Three"; AgencyId agencyIdThreeViaCtor = new AgencyId(null, AGENCY_THREE_VALUE); AgencyId agencyIdThreeViaFind = null; try { agencyIdThreeViaFind = AgencyId.find(null, AGENCY_THREE_VALUE); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("AgencyId.find() method threw exception for scheme 'null' and value '" + AGENCY_THREE_VALUE + "' - was AgencyId set to allow any in configuration?"); } Assert.assertEquals(agencyIdThreeViaCtor, agencyIdThreeViaFind); Assert.assertSame(agencyIdThreeViaCtor, agencyIdThreeViaFind); String GPE_ALIAS_SCHEME = "http: ProblemType genProcErrorWithAliasViaFind = null; try { genProcErrorWithAliasViaFind = Version1GeneralProcessingError.find( GPE_ALIAS_SCHEME, Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED.getValue()); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("Version1GeneralProcessingError.find() method threw exception for scheme '" + GPE_ALIAS_SCHEME + "' and value '" + Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED + "' - is " + GPE_ALIAS_SCHEME + " set as an alias for " + Version1GeneralProcessingError.VERSION_1_GENERAL_PROCESSING_ERROR + "?"); } Assert.assertEquals(genProcErrorWithAliasViaFind, Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED); Assert.assertSame(genProcErrorWithAliasViaFind, Version1GeneralProcessingError.AGENCY_AUTHENTICATION_FAILED); Language languageCopy = new Language(Version1Language.ZAP.getScheme(), Version1Language.ZAP.getValue()); Assert.assertEquals(Version1Language.ZAP, languageCopy); Language foundLanguage = null; try { foundLanguage = Language.find(Version1Language.ZAP.getScheme(), Version1Language.ZAP.getValue()); Assert.assertEquals(Version1Language.ZAP, foundLanguage); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.fail("Version1Language.ZAP not found via call to Language.find() method " + " - was Version1Language loaded in configuration?"); } String BAD_LANGUAGE_SCHEME = "Fake scheme"; String BAD_LANGUAGE_VALUE = "Fake value"; String GOOD_LANGUAGE_SCHEME = Version1Language.ZAP.getScheme(); String GOOD_LANGUAGE_VALUE = Version1Language.ZAP.getValue(); try { Language unfoundSchemeLanguage = Language.find(BAD_LANGUAGE_SCHEME, GOOD_LANGUAGE_VALUE); Assert.fail("Language.find(\"" + BAD_LANGUAGE_SCHEME + "\"), \"" + GOOD_LANGUAGE_VALUE + "\") succeeded when it should fail as there's no such language Scheme URI."); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.assertTrue(e.getLocalizedMessage().matches("(?i).*no match found for scheme .*")); } try { Language unfoundValueLanguage = Language.find(GOOD_LANGUAGE_SCHEME, BAD_LANGUAGE_VALUE); Assert.fail("Language.find(\"" + GOOD_LANGUAGE_SCHEME + "\"), \"" + BAD_LANGUAGE_VALUE + "\") " + " succeeded when it should fail as there's no such value in the Language Scheme(s)."); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.assertTrue(e.getLocalizedMessage().matches("(?i).*no match found for scheme .*")); } SchemeValuePair.mapBehavior(ComponentIdentifierType.class.getName(), SchemeValueBehavior.DEFINED_ONLY); try { ComponentIdentifierType.find("undefined scheme", "eng"); } catch (ServiceException e) { LOG.debug("Exception thrown:", e); Assert.assertTrue(e.getLocalizedMessage().matches("(?i).*no match found for scheme .*DEFINED_ONLY.*")); } }
protected static <SVP extends SchemeValuePair> SchemeValuePair find(final String scheme, final String value, List<SVP> values, Class<SVP> svpClass) throws ServiceException { SchemeValuePair match = searchList(scheme, value, values); if (match == null) { SchemeValueBehavior behavior = BEHAVIOR_BY_CLASS_NAME_MAP.get(svpClass.getName()); if (behavior == null) { behavior = SchemeValueBehavior.UNSET; } match = behavior.applyBehavior(scheme, value, values, svpClass); } return match; }
SchemeValuePair { protected static <SVP extends SchemeValuePair> SchemeValuePair find(final String scheme, final String value, List<SVP> values, Class<SVP> svpClass) throws ServiceException { SchemeValuePair match = searchList(scheme, value, values); if (match == null) { SchemeValueBehavior behavior = BEHAVIOR_BY_CLASS_NAME_MAP.get(svpClass.getName()); if (behavior == null) { behavior = SchemeValueBehavior.UNSET; } match = behavior.applyBehavior(scheme, value, values, svpClass); } return match; } }
SchemeValuePair { protected static <SVP extends SchemeValuePair> SchemeValuePair find(final String scheme, final String value, List<SVP> values, Class<SVP> svpClass) throws ServiceException { SchemeValuePair match = searchList(scheme, value, values); if (match == null) { SchemeValueBehavior behavior = BEHAVIOR_BY_CLASS_NAME_MAP.get(svpClass.getName()); if (behavior == null) { behavior = SchemeValueBehavior.UNSET; } match = behavior.applyBehavior(scheme, value, values, svpClass); } return match; } SchemeValuePair(String scheme, String value);  SchemeValuePair(String value); }
SchemeValuePair { protected static <SVP extends SchemeValuePair> SchemeValuePair find(final String scheme, final String value, List<SVP> values, Class<SVP> svpClass) throws ServiceException { SchemeValuePair match = searchList(scheme, value, values); if (match == null) { SchemeValueBehavior behavior = BEHAVIOR_BY_CLASS_NAME_MAP.get(svpClass.getName()); if (behavior == null) { behavior = SchemeValueBehavior.UNSET; } match = behavior.applyBehavior(scheme, value, values, svpClass); } return match; } SchemeValuePair(String scheme, String value);  SchemeValuePair(String value); static void allowNullScheme(String... classNames); static void mapBehavior(String className, SchemeValueBehavior behavior); static void setSchemeURIAlias(String canonicalURI, String aliasURI); String getScheme(); String getValue(); @Override boolean equals(Object o); boolean isComparableSVPSubclass(Object o); boolean matches(SchemeValuePair svp); boolean matches(String scheme, String value); boolean areNullSchemesAllowed(); @Override String toString(); }
SchemeValuePair { protected static <SVP extends SchemeValuePair> SchemeValuePair find(final String scheme, final String value, List<SVP> values, Class<SVP> svpClass) throws ServiceException { SchemeValuePair match = searchList(scheme, value, values); if (match == null) { SchemeValueBehavior behavior = BEHAVIOR_BY_CLASS_NAME_MAP.get(svpClass.getName()); if (behavior == null) { behavior = SchemeValueBehavior.UNSET; } match = behavior.applyBehavior(scheme, value, values, svpClass); } return match; } SchemeValuePair(String scheme, String value);  SchemeValuePair(String value); static void allowNullScheme(String... classNames); static void mapBehavior(String className, SchemeValueBehavior behavior); static void setSchemeURIAlias(String canonicalURI, String aliasURI); String getScheme(); String getValue(); @Override boolean equals(Object o); boolean isComparableSVPSubclass(Object o); boolean matches(SchemeValuePair svp); boolean matches(String scheme, String value); boolean areNullSchemesAllowed(); @Override String toString();  }