@Test
  public void testWFSTransactionInsert() throws Exception {
    TransactionType t = WfsFactory.eINSTANCE.createTransactionType();
    InsertElementType ie = WfsFactory.eINSTANCE.createInsertElementType();
    t.getInsert().add(ie);

    // ie.setSrsName(new URI("epsg:4326"));

    BoundingBox expected =
        new ReferencedEnvelope(53.73, 40, -60, -95.1193, CRS.decode("EPSG:4326"));

    SimpleFeatureType ft = createNiceMock(SimpleFeatureType.class);
    expect(ft.getTypeName()).andReturn("acme:foo").anyTimes();
    replay(ft);

    SimpleFeature f = createNiceMock(SimpleFeature.class);
    expect(f.getBounds()).andReturn(expected).anyTimes();
    expect(f.getType()).andReturn(ft).anyTimes();
    replay(f);

    ie.getFeature().add(f);

    Operation op = op("Transaction", "WFS", "1.1.0", t);
    callback.operationDispatched(new Request(), op);

    assertEquals("acme:foo", data.getResources().get(0));

    // xMin,yMin -95.1193,40 : xMax,yMax -60,53.73
    BBoxAsserts.assertEqualsBbox(expected, data.getBbox(), 0.01);
  }
  @Test
  public void testWFSTransaction() throws Exception {
    TransactionType t = WfsFactory.eINSTANCE.createTransactionType();
    org.opengis.filter.Filter f1 = parseFilter("BBOX(the_geom, 40, -90, 45, -60)");
    org.opengis.filter.Filter f2 =
        parseFilter("BBOX(the_geom, 5988504.35,851278.90, 7585113.55,1950872.01)");

    UpdateElementType ue = WfsFactory.eINSTANCE.createUpdateElementType();
    ue.setTypeName(new QName("http://acme.org", "foo", "acme"));
    ue.setFilter(f1);
    t.getUpdate().add(ue);

    DeleteElementType de = WfsFactory.eINSTANCE.createDeleteElementType();
    de.setTypeName(new QName("http://acme.org", "bar", "acme"));
    de.setFilter(f2);
    t.getDelete().add(de);

    Operation op = op("Transaction", "WFS", "1.1.0", t);
    callback.operationDispatched(new Request(), op);

    assertEquals("acme:foo", data.getResources().get(0));
    assertEquals("acme:bar", data.getResources().get(1));
    BoundingBox expected =
        new ReferencedEnvelope(53.73, 40, -60, -95.1193, CRS.decode("EPSG:4326"));
    // xMin,yMin -95.1193,40 : xMax,yMax -60,53.73
    BBoxAsserts.assertEqualsBbox(expected, data.getBbox(), 0.01);
  }
  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"));
  }