@Test
  public void singleLongOption() {
    OptionSet options = parser.parse("--verbose");

    assertTrue(options.has("verbose"));
    assertEquals(emptyList(), options.valuesOf("verbose"));
    assertEquals(emptyList(), options.nonOptionArguments());
  }
  @Test
  public void abbreviationIsALegalOption() {
    OptionSet options = parser.parse("--verb");

    assertFalse(options.has("verbose"));
    assertTrue(options.has("verb"));
    assertEquals(emptyList(), options.valuesOf("verb"));
    assertEquals(emptyList(), options.nonOptionArguments());
  }
  @Test
  public void abbreviation() {
    OptionSet options = parser.parse("--W", "silent");

    assertOptionDetected(options, "Wally");
    assertOptionNotDetected(options, "W");
    assertEquals(singletonList("silent"), options.valuesOf("Wally"));
    assertEquals(emptyList(), options.nonOptionArguments());
  }
  @Test
  public void wExtensionWithLongOptionWithoutAnArgument() {
    OptionSet options = parser.parse("-W", "silent");

    assertOptionNotDetected(options, "W");
    assertOptionDetected(options, "silent");
    assertEquals(emptyList(), options.valuesOf("silent"));
    assertEquals(emptyList(), options.nonOptionArguments());
  }
Ejemplo n.º 5
0
  /** This time we mix some conflicting and non conflicting changes */
  public void testConflicts() throws Exception {
    VersioningFeatureStore restricted =
        (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
    SimpleFeatureType schema = restricted.getSchema();
    // modify the fourth feature, change its cat from 400 to 450
    Id updateFilter =
        ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
    restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
    // a update that will generate a conflict
    updateFilter =
        ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
    restricted.modifyFeatures(schema.getDescriptor("cat"), 347, updateFilter);
    // an update that will generate a clean merge
    updateFilter =
        ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
    restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);

    // execute the postDiff
    MockHttpServletResponse response =
        postAsServletResponse(root(true), loadTextResource("PostDiffInitial.xml"));
    checkPostDiffSuccessResponse(response);

    // check there is one conflict and one clean merge
    assertEquals(1, gss.getActiveConflicts("restricted").size());
    assertEquals(1, gss.getCleanMerges("restricted", 7).size());

    // run GetDiff
    response = postAsServletResponse(root(true), loadTextResource("GetDiffInitial.xml"));
    validate(response);
    Document dom = dom(response);
    // print(dom);

    // check the document contents are the expected ones
    // ... check the main element
    assertXpathEvaluatesTo("-1", "/gss:GetDiffResponse/@fromVersion", dom);
    assertXpathEvaluatesTo("7", "/gss:GetDiffResponse/@toVersion", dom);
    assertXpathEvaluatesTo("sf:restricted", "/gss:GetDiffResponse/@typeName", dom);
    // ... check we get only one change, the non conflicting one
    assertXpathEvaluatesTo("1", "count(/gss:GetDiffResponse/gss:Changes)", dom);
    // check the update one
    assertXpathEvaluatesTo(
        "sf:restricted", "/gss:GetDiffResponse/gss:Changes/wfs:Update/@typeName", dom);
    assertXpathEvaluatesTo(
        "1", "count(/gss:GetDiffResponse/gss:Changes/wfs:Update/ogc:Filter/ogc:FeatureId)", dom);
    assertXpathEvaluatesTo(
        "restricted.1b99be2b-2480-4742-ad52-95c294efda3b",
        "/gss:GetDiffResponse/gss:Changes/wfs:Update/ogc:Filter/ogc:FeatureId/@fid",
        dom);
    assertXpathEvaluatesTo(
        "1", "count(/gss:GetDiffResponse/gss:Changes/wfs:Update/wfs:Property)", dom);
    assertXpathEvaluatesTo(
        "cat", "/gss:GetDiffResponse/gss:Changes/wfs:Update/wfs:Property/wfs:Name", dom);
    assertXpathEvaluatesTo(
        "450", "/gss:GetDiffResponse/gss:Changes/wfs:Update/wfs:Property/wfs:Value", dom);
  }
 @Test
 public void shortOptionsInDifferentOrder() {
   OptionSet options = parser.parse("-fxo");
   assertFalse(options.has("fox"));
   assertTrue(options.has("f"));
   assertFalse(options.has("o"));
   assertTrue(options.has("x"));
   assertEquals(singletonList("o"), options.valuesOf("x"));
 }
 @Test
 public void resolvesToShortOptionsWithArgumentFollowingX() {
   OptionSet options = parser.parse("-foxbar");
   assertFalse(options.has("fox"));
   assertTrue(options.has("f"));
   assertTrue(options.has("o"));
   assertTrue(options.has("x"));
   assertEquals(singletonList("bar"), options.valuesOf("x"));
 }
  @Test
  public void withArgumentComingAfterCluster() {
    OptionSet options = parser.parse("-fox", "bar");

    assertTrue(options.has("fox"));
    assertFalse(options.has("f"));
    assertFalse(options.has("o"));
    assertFalse(options.has("x"));
    assertEquals(singletonList("bar"), options.nonOptionArguments());
  }
  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"));
  }
 @Test
 public void shouldBeTolerantOfDissapearingDirectories() throws Exception {
   detector =
       new FileChangeDetector() {
         @Override
         protected File[] childrenOf(File directory) {
           return null;
         }
       };
   detector.setClasspathProvider(classpath);
   assertEquals(emptySet(), detector.findChangedFiles());
 }
Ejemplo n.º 11
0
  @Test
  public void supportsPosixlyCorrectBehavior() {
    OptionParser parser = new OptionParser("i:j::k");
    String[] arguments = {
      "-ibar", "-i", "junk", "xyz", "-jixnay", "foo", "-k", "blah", "--", "bah"
    };

    OptionSet options = parser.parse(arguments);

    assertTrue(options.has("i"));
    assertTrue(options.has("j"));
    assertTrue(options.has("k"));
    assertEquals(asList("bar", "junk"), options.valuesOf("i"));
    assertEquals(singletonList("ixnay"), options.valuesOf("j"));
    assertEquals(asList("xyz", "foo", "blah", "bah"), options.nonOptionArguments());

    parser.posixlyCorrect(true);
    options = parser.parse(arguments);

    assertTrue(options.has("i"));
    assertFalse(options.has("j"));
    assertFalse(options.has("k"));
    assertEquals(asList("bar", "junk"), options.valuesOf("i"));
    assertEquals(emptyList(), options.valuesOf("j"));
    assertEquals(
        asList("xyz", "-jixnay", "foo", "-k", "blah", "--", "bah"), options.nonOptionArguments());
  }
Ejemplo n.º 12
0
  public void testCleanMerge() throws Exception {
    // grab the datastore
    VersioningFeatureStore restricted =
        (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
    SimpleFeatureType schema = restricted.getSchema();
    // make the same changes as in the post diff
    Id updateFilter =
        ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
    restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
    // remove the third feature
    Id removeFilter =
        ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
    restricted.removeFeatures(removeFilter);
    assertEquals(3, restricted.getCount(Query.ALL));

    // get the response and do the basic checks
    MockHttpServletResponse response =
        postAsServletResponse(root(true), loadTextResource("PostDiffInitial.xml"));
    checkPostDiffSuccessResponse(response);

    // check there are no conflicts
    assertEquals(0, gss.getActiveConflicts("restricted").size());

    // run GetDiff
    response = postAsServletResponse(root(true), loadTextResource("GetDiffInitial.xml"));
    validate(response);
    Document dom = dom(response);
    // print(dom);

    // we should have got back an empty transaction
    // ... check the main element
    assertXpathEvaluatesTo("-1", "/gss:GetDiffResponse/@fromVersion", dom);
    assertXpathEvaluatesTo("6", "/gss:GetDiffResponse/@toVersion", dom);
    assertXpathEvaluatesTo("sf:restricted", "/gss:GetDiffResponse/@typeName", dom);
    // check the transaction is empty
    assertXpathEvaluatesTo("0", "count(/gss:GetDiffResponse/gss:Changes/*)", dom);
  }
  @Test
  public void shouldLookForClassesInTargetDirectories() throws Exception {
    newDir = new File("tempClassDir");
    List<File> buildPaths = asList(newDir);
    ClasspathProvider classpath =
        new StandaloneClasspath(
            buildPaths,
            FakeEnvironments.systemClasspath() + pathSeparator + newDir.getAbsolutePath());

    String classname = "org.fakeco.Foobar";
    createClass(classname);

    builder = new JavaClassBuilder(classpath);
    JavaClass javaClass = builder.createClass(classname);
    assertEquals(classname, javaClass.getName());
    assertFalse(javaClass.isATest());
  }
Ejemplo n.º 14
0
  public void testNoConflictingChanges() throws Exception {
    // grab the datastore so that we can make some changes that will not generate conflicts
    VersioningFeatureStore restricted =
        (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
    SimpleFeatureType schema = restricted.getSchema();
    // modify the fourth feature, change its cat from 400 to 450
    Id updateFilter =
        ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
    restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
    // 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));

    // execute the postDiff
    MockHttpServletResponse response =
        postAsServletResponse(root(true), loadTextResource("PostDiffInitial.xml"));
    checkPostDiffSuccessResponse(response);

    // check there are no conflicts
    assertEquals(0, gss.getActiveConflicts("restricted").size());

    // run GetDiff
    response = postAsServletResponse(root(true), loadTextResource("GetDiffInitial.xml"));
    validate(response);
    Document dom = dom(response);
    // print(dom);

    // check the document contents are the expected ones
    // ... check the main element
    assertXpathEvaluatesTo("-1", "/gss:GetDiffResponse/@fromVersion", dom);
    assertXpathEvaluatesTo("6", "/gss:GetDiffResponse/@toVersion", dom);
    assertXpathEvaluatesTo("sf:restricted", "/gss:GetDiffResponse/@typeName", dom);
    // check the transaction has two elements
    assertXpathEvaluatesTo("2", "count(/gss:GetDiffResponse/gss:Changes/*)", dom);
    // check the update one
    assertXpathEvaluatesTo(
        "sf:restricted", "/gss:GetDiffResponse/gss:Changes/wfs:Update/@typeName", dom);
    assertXpathEvaluatesTo(
        "1", "count(/gss:GetDiffResponse/gss:Changes/wfs:Update/ogc:Filter/ogc:FeatureId)", dom);
    assertXpathEvaluatesTo(
        "restricted.1b99be2b-2480-4742-ad52-95c294efda3b",
        "/gss:GetDiffResponse/gss:Changes/wfs:Update/ogc:Filter/ogc:FeatureId/@fid",
        dom);
    assertXpathEvaluatesTo(
        "1", "count(/gss:GetDiffResponse/gss:Changes/wfs:Update/wfs:Property)", dom);
    assertXpathEvaluatesTo(
        "cat", "/gss:GetDiffResponse/gss:Changes/wfs:Update/wfs:Property/wfs:Name", dom);
    assertXpathEvaluatesTo(
        "450", "/gss:GetDiffResponse/gss:Changes/wfs:Update/wfs:Property/wfs:Value", dom);
    // check the delete one
    assertXpathEvaluatesTo(
        "sf:restricted", "/gss:GetDiffResponse/gss:Changes/wfs:Delete/@typeName", dom);
    assertXpathEvaluatesTo(
        "restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a",
        "/gss:GetDiffResponse/gss:Changes/wfs:Delete/ogc:Filter/ogc:FeatureId/@fid",
        dom);
    assertXpathEvaluatesTo(
        "restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a",
        "/gss:GetDiffResponse/gss:Changes/wfs:Delete/ogc:Filter/ogc:FeatureId/@fid",
        dom);
  }