@Override
  protected void setUpInternal() throws Exception {
    // configure the GSS service
    GeoServer gs = getGeoServer();
    GSSInfo gssInfo = gs.getService(GSSInfo.class);
    gssInfo.setMode(GSSMode.Central);
    gssInfo.setVersioningDataStore(getCatalog().getDataStoreByName("synch"));
    gs.save(gssInfo);

    // initialize the GSS service
    Map gssBeans = applicationContext.getBeansOfType(DefaultGeoServerSynchronizationService.class);
    gss = (DefaultGeoServerSynchronizationService) gssBeans.values().iterator().next();
    gss.core.ensureCentralEnabled();

    // grab the synch manager
    synch =
        (SynchronizationManager)
            applicationContext
                .getBeansOfType(SynchronizationManager.class)
                .values()
                .iterator()
                .next();

    // disable automated scheduling, we control how does what here
    Timer timer = (Timer) applicationContext.getBean("gssTimerFactory");
    timer.cancel();

    // make some tables synchronised
    synchStore = (VersioningDataStore) getCatalog().getDataStoreByName("synch").getDataStore(null);
    FeatureStore<SimpleFeatureType, SimpleFeature> fs =
        (FeatureStore<SimpleFeatureType, SimpleFeature>) synchStore.getFeatureSource(SYNCH_TABLES);
    long restrectedId = addFeature(fs, "restricted", "2");
    long roadsId = addFeature(fs, "roads", "2");
    synchStore.setVersioned("restricted", true, null, null);
    synchStore.setVersioned("roads", true, null, null);

    // add some units
    fsUnits =
        (FeatureStore<SimpleFeatureType, SimpleFeature>) synchStore.getFeatureSource(SYNCH_UNITS);
    long mangoId =
        addFeature(
            fsUnits,
            "unit1",
            "http://localhost:8081/geoserver/ows",
            null,
            null,
            null,
            null,
            60,
            10,
            false);

    // link units and tables
    fsUnitTables =
        (FeatureStore<SimpleFeatureType, SimpleFeature>)
            synchStore.getFeatureSource(SYNCH_UNIT_TABLES);
    addFeature(fsUnitTables, mangoId, restrectedId, null, null, null, null);
    // addFeature(fsUnitTables, mangoId, roadsId, null, null, null, null);
  }
  public void testLocalChanges() throws Exception {
    // apply a local change on Central so that we'll get a non empty transaction sent to the client
    VersioningFeatureStore restricted =
        (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
    SimpleFeatureType schema = restricted.getSchema();
    // remove the third feature
    Id removeFilter =
        ff.id(singleton(ff.featureId("restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a")));
    restricted.removeFeatures(removeFilter);
    assertEquals(3, restricted.getCount(Query.ALL));

    // build the expected PostDiff request
    QName typeName = new QName("http://www.openplans.org/spearfish", "restricted");
    PostDiffType postDiff = new PostDiffType();
    postDiff.setFromVersion(-1);
    postDiff.setToVersion(3);
    postDiff.setTypeName(typeName);
    TransactionType changes = WfsFactory.eINSTANCE.createTransactionType();
    DeleteElementType delete = WfsFactory.eINSTANCE.createDeleteElementType();
    delete.setTypeName(typeName);
    delete.setFilter(removeFilter);
    changes.getDelete().add(delete);
    postDiff.setTransaction(changes);

    // create mock objects that will check the calls are flowing as expected
    GSSClient client = createMock(GSSClient.class);
    expect(client.getCentralRevision((QName) anyObject())).andReturn(new Long(-1));
    client.postDiff(postDiff);
    expect(client.getDiff((GetDiffType) anyObject())).andReturn(new GetDiffResponseType());
    replay(client);
    GSSClientFactory factory = createMock(GSSClientFactory.class);
    expect(factory.createClient(new URL("http://localhost:8081/geoserver/ows"), null, null))
        .andReturn(client);
    replay(factory);

    synch.clientFactory = factory;

    // perform synch
    Date start = new Date();
    synch.synchronizeOustandlingLayers();
    Date end = new Date();

    // check we stored the last synch marker
    SimpleFeature f =
        getSingleFeature(fsUnitTables, ff.equal(ff.property("table_id"), ff.literal(1), false));
    Date lastSynch = (Date) f.getAttribute("last_synchronization");
    assertNotNull(lastSynch);
    assertTrue(lastSynch.compareTo(start) >= 0 && lastSynch.compareTo(end) <= 0);
    assertNull(f.getAttribute("last_failure"));

    // check we marked the unit as succeded
    f = getSingleFeature(fsUnits, ff.equal(ff.property("unit_name"), ff.literal("unit1"), false));
    assertFalse((Boolean) f.getAttribute("errors"));
  }