@Test
 public void ensureSaveMethodWithDefaultPrincipalAttribute() {
   final RegexRegisteredService r = new RegexRegisteredService();
   r.setName("testSaveMethodWithDefaultPrincipalAttribute");
   r.setServiceId("testId");
   r.setTheme("theme");
   r.setDescription("description");
   r.setUsernameAttributeProvider(new PrincipalAttributeRegisteredServiceUsernameProvider("cn"));
   final RegisteredService r2 = this.dao.save(r);
   assertEquals(r2, r);
 }
  @Test
  public void checkSaveMethodWithNonExistentServiceAndNoAttributes() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveMethodWithNonExistentServiceAndNoAttributes");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
  }
  @Test
  public void verifySaveMethodWithExistingServiceNoAttribute() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveMethodWithExistingServiceNoAttribute");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");
    this.dao.save(r);
    r.setTheme("mytheme");

    this.dao.save(r);

    final RegisteredService r3 = this.dao.findServiceById(r.getId());
    assertEquals(r, r3);
  }
  @Test
  public void verifySaveAttributeReleasePolicy() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("testSaveAttributeReleasePolicy");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");
    r.setAttributeReleasePolicy(new ReturnAllAttributeReleasePolicy());

    final RegisteredService r2 = this.dao.save(r);
    final RegisteredService r3 = this.dao.findServiceById(r2.getId());

    assertEquals(r, r2);
    assertEquals(r2, r3);
    assertNotNull(r3.getAttributeReleasePolicy());
    assertEquals(r2.getAttributeReleasePolicy(), r3.getAttributeReleasePolicy());
  }
 @Test
 public void verifySaveMethodWithDefaultAnonymousAttribute() {
   final RegexRegisteredService r = new RegexRegisteredService();
   r.setName("testSaveMethodWithDefaultAnonymousAttribute");
   r.setServiceId("testId");
   r.setTheme("theme");
   r.setDescription("description");
   r.setUsernameAttributeProvider(
       new AnonymousRegisteredServiceUsernameAttributeProvider(
           new ShibbolethCompatiblePersistentIdGenerator("helloworld")));
   final RegisteredService r2 = this.dao.save(r);
   this.dao.load();
   final RegisteredService r3 = this.dao.findServiceById(r2.getId());
   final AnonymousRegisteredServiceUsernameAttributeProvider anon =
       (AnonymousRegisteredServiceUsernameAttributeProvider) r3.getUsernameAttributeProvider();
   final ShibbolethCompatiblePersistentIdGenerator ss =
       (ShibbolethCompatiblePersistentIdGenerator) anon.getPersistentIdGenerator();
   assertEquals(new String(ss.getSalt()), "helloworld");
   assertEquals(r2, r3);
 }
  @Test
  public void execSaveWithAuthnMethodPolicy() {
    final RegexRegisteredService r = new RegexRegisteredService();
    r.setName("execSaveWithAuthnMethodPolicy");
    r.setServiceId("testId");
    r.setTheme("theme");
    r.setDescription("description");

    final DefaultRegisteredServiceMultifactorPolicy policy =
        new DefaultRegisteredServiceMultifactorPolicy();
    policy.setFailureMode(RegisteredServiceMultifactorPolicy.FailureModes.PHANTOM);

    final Set<String> set = new HashSet<>();
    set.add("duoAuthenticationProvider");
    policy.setMultifactorAuthenticationProviders(set);
    policy.setPrincipalAttributeNameTrigger("memberOf");
    policy.setPrincipalAttributeValueToMatch("cas|CAS|admin");
    r.setMultifactorPolicy(policy);
    final RegisteredService r2 = this.dao.save(r);
    assertEquals(r2, r);
  }