public static OMEROMetadataStoreClient mockStore(ServiceFactory sf, String password)
      throws Exception {

    System.setProperty("omero.testing", "true");
    OmeroContext inner = sf.getContext();
    OmeroContext outer =
        new OmeroContext(
            new String[] {
              "classpath:ome/services/messaging.xml", // To share events
              "classpath:ome/formats/fixture.xml",
              "classpath:ome/services/blitz-servantDefinitions.xml",
              "classpath:ome/services/throttling/throttling.xml",
              "classpath:ome/config.xml"
            },
            false);
    outer.setParent(inner);
    outer.refresh();

    EventContext ec = sf.getAdminService().getEventContext();
    String username = ec.getCurrentUserName();
    long groupid = ec.getCurrentGroupId();

    MockFixture fixture = new MockFixture(new MockObjectTestCase() {}, outer);
    omero.client client = fixture.newClient();
    // Fixing group permissions from 4.2.0
    client
        .createSession(username, password)
        .setSecurityContext(new omero.model.ExperimenterGroupI(groupid, false));
    OMEROMetadataStoreClient store = new OMEROMetadataStoreClient();
    store.initialize(client);
    return store;
  }
  @Test
  public void testUserCanChangeOwnPassword() throws Exception {
    Experimenter e = createNewUser(rootAdmin);
    resetPasswordTo_ome(e);
    assertCanLogin(e.getOmeName(), "ome");

    ServiceFactory userServices = new ServiceFactory(new Login(e.getOmeName(), "ome"));
    userServices.getAdminService().changePassword("test");
    assertCanLogin(e.getOmeName(), "test");
    assertCannotLogin(e.getOmeName(), "ome");
  }
  @Test(expectedExceptions = SecurityViolation.class)
  public void testUserCantChangeOthersPassword() throws Exception {
    Experimenter e = createNewUser(getSudoAdmin("ome"));
    resetPasswordTo_ome(e);
    assertCanLogin(e.getOmeName(), "ome");

    Experimenter target = createNewUser(getSudoAdmin("ome"));
    resetPasswordTo_ome(target);
    assertCanLogin(target.getOmeName(), "ome");

    ServiceFactory userServices = new ServiceFactory(new Login(e.getOmeName(), "ome"));
    userServices.getAdminService().changeUserPassword(target.getOmeName(), "test");
  }