/**
  * Tests the {@link LaunchConfiguration#setName} method
  *
  * @throws Exception
  */
 public void testSetName() throws Exception {
   assertEquals("The default name should be: 'Test'", config.getName(), "Test");
   config.setNameProxy("newname");
   assertEquals("The new name should be: 'newname'", config.getName(), "newname");
   // reset the name
   config.setNameProxy("Test");
 }
示例#2
0
  /**
   * Verifies that a list of three non-nested transactions all persist correctly.
   *
   * @throws Exception
   */
  public void testPersistTransactions() throws Exception {
    AnzoClient client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client.setNotificationEnabled(false);
    try {
      client1.clear();

      client1.begin();
      ClientGraph replicaGraph = client1.getReplicaGraph(TestData.graph2);
      replicaGraph.add(TestData.stmt2);
      client1.commit();

      client1.begin();
      replicaGraph.add(TestData.stmt3);
      client1.commit();

      client1.begin();
      replicaGraph.add(TestData.stmt4);
      client1.commit();
    } finally {
      client1.close();
    }

    AnzoClient client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    try {
      assertEquals(3, client2.transactionQueue.committedTransactions.size());

      ClientGraph graph = client2.getReplicaGraph(TestData.graph2);
      assertTrue(graph.contains(TestData.stmt2));
      assertTrue(graph.contains(TestData.stmt3));
      assertTrue(graph.contains(TestData.stmt4));
    } finally {
      client2.close();
    }
  }
 @Test
 public void testExceptionHandlerWithFailIgnored() {
   Exception res = null;
   TestConfiguration testConf = new TestConfiguration();
   testConf.setFailIgnored(true);
   try {
     ActionExceptionHandler.handleError(testConf, new TestAction(), "an error message.");
   } catch (ActionException e) {
     fail();
   }
   assertTrue(res == null);
 }
 @Test
 public void testGetPropertyAsDoubleExists() {
   final Configuration configuration = TestConfiguration.create("foo", "1.23");
   final Optional<Double> value = configuration.getPropertyAsDouble("foo");
   Assert.assertTrue(value.isPresent());
   Assert.assertEquals(1.23d, value.get(), 0.001);
 }
 @Test
 public void testGetPropertyAsBooleanExists() {
   final Configuration configuration = TestConfiguration.create("foo", "false");
   final Optional<Boolean> value = configuration.getPropertyAsBoolean("foo");
   Assert.assertTrue(value.isPresent());
   Assert.assertFalse(value.get());
 }
 @Test
 public void testGetPropertyAsShortExists() {
   final Configuration configuration = TestConfiguration.create("foo", "1");
   final Optional<Short> value = configuration.getPropertyAsShort("foo");
   Assert.assertTrue(value.isPresent());
   Assert.assertEquals(1, value.get().shortValue());
 }
  @Test
  public void testConvertMap() throws Exception {
    Map testMap = new HashedMap();
    testMap.put("key1", "value1");
    testMap.put("key2", "value2");
    testMap.put("key3", "value3");

    testConfiguration.setXsltParamTestMap(testMap);

    Map<String, String> result = converter.convert(testConfiguration);

    Assert.assertEquals(4, result.size());

    String actualMapXml = result.get("testMap");

    String entry1 = "<entry key=\"key1\" value=\"value1\"/>";
    String entry2 = "<entry key=\"key2\" value=\"value2\"/>";
    String entry3 = "<entry key=\"key3\" value=\"value3\"/>";

    Assert.assertTrue(actualMapXml.contains(entry1));
    Assert.assertTrue(actualMapXml.contains(entry2));
    Assert.assertTrue(actualMapXml.contains(entry3));

    Assert.assertTrue(
        actualMapXml
            .replace(entry1, "")
            .replace(entry2, "")
            .replace(entry3, "")
            .equals("<map></map>"));
  }
 @Test
 public void testGetPropertyAsLongExists() {
   final Configuration configuration = TestConfiguration.create("foo", "1");
   final Optional<Long> value = configuration.getPropertyAsLong("foo");
   Assert.assertTrue(value.isPresent());
   Assert.assertEquals(1L, value.get().longValue());
 }
 @Test
 public void testGetAsMissing() {
   final Configuration configuration = TestConfiguration.createNull();
   @SuppressWarnings("unchecked")
   final Map<String, String> value =
       (Map<String, String>) configuration.getAs(Map.class, Collections.emptyMap());
   Assert.assertTrue(value.isEmpty());
 }
 @Test
 public void testGetRequiredAsExists() {
   final Configuration configuration = TestConfiguration.create("foo", "bar");
   @SuppressWarnings("unchecked")
   final Map<String, String> value = (Map<String, String>) configuration.getRequiredAs(Map.class);
   Assert.assertEquals(1, value.size());
   Assert.assertEquals("bar", value.get("foo"));
 }
  @Test
  public void testConvertPrimitives() throws Exception {
    String testString = "A test xslt string";

    testConfiguration.setXsltParamTestString(testString);
    testConfiguration.setXsltParamTestInt(123);
    testConfiguration.setXsltParamTestBoolean(true);
    testConfiguration.setXsltParamTestLong(9999999999999l);

    Map<String, String> result = converter.convert(testConfiguration);

    Assert.assertEquals(4, result.size());

    Assert.assertEquals(testString, result.get("testString"));
    Assert.assertEquals("123", result.get("testInt"));
    Assert.assertEquals("true", result.get("testBoolean"));
    Assert.assertEquals("9999999999999", result.get("testLong"));
  }
示例#12
0
 /**
  * verify a commit called with no begin is a no-op and does not throw an exception.
  *
  * @throws Exception
  */
 public void testNoOpCommit() throws Exception {
   AnzoClient client = new AnzoClient(TestConfiguration.getBasicConfiguration());
   try {
     client.clear();
     client.commit();
   } finally {
     client.close();
   }
 }
示例#13
0
  /**
   * Decorate a set of tests to use a single use database with logDevice pointing a log directory to
   * non-default location
   */
  public static Test logDeviceAttributeDatabase(Test test, final String logDevice) {
    Properties attributes = new Properties();
    if (logDevice != null) {
      attributes.setProperty("logDevice", logDevice);
    }

    test = TestConfiguration.singleUseDatabaseDecorator(test);
    return attributesDatabase(attributes, test);
  }
示例#14
0
  /**
   * Decorate a test (or suite of tests) to use a single use database as the default database with a
   * specified set connection attributes.
   *
   * @param attributes properties to set in the connection URL or in the connectionAttributes of a
   *     data source when connecting to the database
   * @param test Test to decorate
   * @return Decorated test
   */
  public static Test attributesDatabase(final Properties attributes, Test test) {
    test =
        new ChangeConfigurationSetup(test) {
          TestConfiguration getNewConfiguration(TestConfiguration old) {
            return old.addConnectionAttributes(attributes);
          }
        };

    return TestConfiguration.singleUseDatabaseDecorator(test);
  }
示例#15
0
  /**
   * Make sure an exception is thrown if an attempt is made to create more than one client that uses
   * the same container name, meaning they would be using the persistent database tables, which is
   * not allowed.
   *
   * @throws Exception
   */
  public void testIllegalSharedDatabase() throws Exception {
    AnzoClient client1 = null;
    AnzoClient client2 = null;
    try {
      AnzoException exception = null;
      try {
        Properties properties = TestUtilities.getProperties();
        AnzoClientProperties.setPersistenceEnabled(properties, true);
        client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
        client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());

      } catch (AnzoException e) {
        exception = e;
      }
      assertNotNull(exception);
    } finally {
      if (client1 != null) client1.close();
      if (client2 != null) client2.close();
    }
  }
示例#16
0
  /**
   * Verifies that replicated Quads are persisted correctly.
   *
   * <p>See also testPersistTransaction, which verifies Quads that have not been replicated (and are
   * in the transaction queue) are persisted correctly.
   *
   * @throws Exception
   */
  public void testPersistQuad() throws Exception {
    AnzoClient client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client.setNotificationEnabled(false);
    try {
      client1.clear();

      ClientGraph graph = client1.getReplicaGraph(TestData.graph1);
      graph.add(TestData.stmt1);
      client1.quadStore.add(TestData.stmt1);
    } finally {
      client1.close();
    }
    AnzoClient client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client2.setNotificationEnabled(false);
    try {
      ClientGraph graph = client2.getReplicaGraph(TestData.graph1);
      assertTrue(graph.contains(TestData.stmt1));
    } finally {
      client2.close();
    }
  }
示例#17
0
  /**
   * Verifies that all the fields of a precondition are persisted correctly.
   *
   * @throws Exception
   */
  public void testPersistPrecondition() throws Exception {
    String preconditionQuery = "ASK WHERE (?s ?p ?o)";

    AnzoClient client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client.setNotificationEnabled(false);
    try {
      client1.clear();
      Precondition precondition =
          new Precondition(
              Collections.singleton(TestData.graph1),
              Collections.singleton(TestData.graph2),
              preconditionQuery,
              true);

      client1.begin(Collections.<IPrecondition>singleton(precondition));
      ClientGraph replicaGraph = client1.getReplicaGraph(TestData.graph2);
      replicaGraph.add(TestData.stmt2);
      client1.commit();
    } finally {
      client1.close();
    }
    AnzoClient client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    try {
      Transaction transaction = client2.transactionQueue.committedTransactions.get(0);
      Set<IPrecondition> preconditions = transaction.preconditions;
      assertNotNull(preconditions);
      Iterator<IPrecondition> iterator = preconditions.iterator();
      assertTrue(iterator.hasNext());
      IPrecondition next = iterator.next();

      assertEquals(preconditionQuery, next.getQuery());
      assertTrue(next.getDefaultGraphUris().contains(TestData.graph1));
      assertTrue(next.getNamedGraphUris().contains(TestData.graph2));
      AskResult result = (AskResult) next.getResult();
      assertTrue(result.getResultValue());
    } finally {
      client2.close();
    }
  }
  /** Only called reflectively. Do not use programmatically. */
  public Junit4TestFixtureRunner(Class<?> klass) throws Throwable {
    super(klass, Collections.<Runner>emptyList());

    String restrictProperty = null;
    String restrictValue = null;
    Class<?> fixtureClass = null;

    String fixtureType = null;
    for (Annotation annotation : getTestClass().getAnnotations()) {
      if ("org.eclipse.mylyn.commons.sdk.util.Junit4TestFixtureRunner.OnlyRunWithProperty"
          .equals(annotation.annotationType().getCanonicalName())) {
        RunOnlyWhenProperty onlyWhenProperty = (RunOnlyWhenProperty) annotation;
        restrictProperty = onlyWhenProperty.property();
        restrictValue = onlyWhenProperty.value();
      }
      if ("org.eclipse.mylyn.commons.sdk.util.Junit4TestFixtureRunner.FixtureDefinition"
          .equals(annotation.annotationType().getCanonicalName())) {
        FixtureDefinition fixtueDef = (FixtureDefinition) annotation;
        fixtureClass = fixtueDef.fixtureClass();
        fixtureType = fixtueDef.fixtureType();
      }
    }
    if (fixtureType != null) {
      List<AbstractTestFixture> parametersList =
          (List<AbstractTestFixture>)
              TestConfiguration.getDefault().discover(fixtureClass, fixtureType);
      List<AbstractTestFixture> fixturesToExecute = new ArrayList<AbstractTestFixture>();
      if (restrictProperty != null) {
        for (AbstractTestFixture abstractFixture : parametersList) {
          String tempProperty = abstractFixture.getProperty(restrictProperty);
          if (tempProperty != null && tempProperty.equals(restrictValue)) {
            fixturesToExecute.add(abstractFixture);
          }
        }
        if (fixturesToExecute.size() > 0) {
          for (int i = 0; i < fixturesToExecute.size(); i++) {
            runners.add(
                new TestClassRunnerForFixture(getTestClass().getJavaClass(), fixturesToExecute, i));
          }
        }
      } else if (parametersList.size() > 0) {
        for (int i = 0; i < parametersList.size(); i++) {
          runners.add(
              new TestClassRunnerForFixture(getTestClass().getJavaClass(), parametersList, i));
        }
      }
    } else {
      throw new InitializationError(
          "Missing Annotation FixtureDefinition for Junit4TestFixtureRunner");
    }
  }
示例#19
0
 /**
  * Verifies inTransaction returns the correct response for the various possible states.
  *
  * @throws Exception
  */
 public void testInTransaction() throws Exception {
   AnzoClient client = new AnzoClient(TestConfiguration.getBasicConfiguration());
   try {
     client.begin(Collections.<IPrecondition>emptySet());
     assertTrue(client.inTransaction());
     client.commit();
     assertFalse(client.inTransaction());
     client.begin(Collections.<IPrecondition>emptySet());
     assertTrue(client.inTransaction());
     client.abort();
     assertFalse(client.inTransaction());
   } finally {
     client.close();
   }
 }
示例#20
0
  /**
   * verify an abort called with no begin is a no-op and does not throw an exception.
   *
   * @throws Exception
   */
  public void testNoOpAbort() throws Exception {
    AnzoClient client = new AnzoClient(TestConfiguration.getBasicConfiguration());
    try {
      client.clear();

      boolean exceptionCought = false;
      try {
        client.abort();
      } catch (Exception e) {
        exceptionCought = true;
      }
      assertFalse(exceptionCought);
    } finally {
      client.close();
    }
  }
 /**
  * Tests the {@link LaunchConfiguration#getFileName} method
  *
  * @throws Exception
  */
 public void testGetFileName() throws Exception {
   String filename = config.getFileNameProxy();
   assertEquals("The filename should be: 'Test.launch'", "Test.launch", filename);
   config.setNameProxy("launch");
   filename = config.getFileNameProxy();
   assertEquals("The filename should be: 'launch.launch'", "launch.launch", filename);
   config.setNameProxy("launch.foo");
   filename = config.getFileNameProxy();
   assertEquals("The filename should be: 'launch.foo.launch'", "launch.foo.launch", filename);
   // reset the name
   config.setNameProxy("Test");
 }
示例#22
0
  /**
   * verifies that statements are added to and removed from the transaction proxy correctly for the
   * following set of operations:
   *
   * <pre>
   *   begin transaction
   *   add stmt2 (and verify)
   *   abort transaction
   *   (verify stmt2 is removed)
   *
   *
   *   begin transaction
   *   add stmt3 (and verify)
   *   commit transaction
   *   (verify stmt3 still exists)
   * </pre>
   *
   * @throws Exception
   */
  public void testSimpleTransactionIsolation() throws Exception {
    AnzoClient client = new AnzoClient(TestConfiguration.getBasicConfiguration());

    // client.setNotificationEnabled(false);
    try {
      ClientGraph replicaGraph = client.getReplicaGraph(TestData.graph1);
      replicaGraph.add(TestData.stmt1);

      assertTrue(replicaGraph.contains(TestData.stmt1));
      assertFalse(replicaGraph.contains(TestData.stmt2));
      assertFalse(replicaGraph.contains(TestData.stmt3));

      client.begin();

      replicaGraph.add(TestData.stmt2);

      assertTrue(replicaGraph.contains(TestData.stmt1));
      assertTrue(replicaGraph.contains(TestData.stmt2));
      assertFalse(replicaGraph.contains(TestData.stmt3));

      client.abort();

      assertTrue(replicaGraph.contains(TestData.stmt1));
      assertFalse(replicaGraph.contains(TestData.stmt2));
      assertFalse(replicaGraph.contains(TestData.stmt3));

      client.begin();

      replicaGraph.add(TestData.stmt3);

      assertTrue(replicaGraph.contains(TestData.stmt1));
      assertFalse(replicaGraph.contains(TestData.stmt2));
      assertTrue(replicaGraph.contains(TestData.stmt3));

      client.commit();

      assertTrue(replicaGraph.contains(TestData.stmt1));
      assertFalse(replicaGraph.contains(TestData.stmt2));
      assertTrue(replicaGraph.contains(TestData.stmt3));
    } finally {
      client.close();
    }
  }
  @Test
  public void testConvertList() throws Exception {
    List testList = new ArrayList();
    testList.add("value1");
    testList.add("value2");
    testList.add("value3");

    testConfiguration.setXsltParamTestList(testList);

    Map<String, String> result = converter.convert(testConfiguration);

    Assert.assertEquals(4, result.size());

    String actualListXml = result.get("testList");

    String expectedListXml =
        "<list><value>value1</value><value>value2</value><value>value3</value></list>";

    Assert.assertEquals(expectedListXml, actualListXml);
  }
 /**
  * Tests the {@link LaunchConfiguration#getSimpleName} method
  *
  * @throws Exception
  * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=332410
  */
 public void testGetSimpleName() throws Exception {
   // filenames with the ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION as an extension
   String name = config.getSimpleNameProxy("launch.launch");
   assertEquals("Did not get expected name: 'launch'", "launch", name);
   name = config.getSimpleNameProxy("launch.foo.launch");
   assertEquals("Did not get expected name: 'launch.foo'", "launch.foo", name);
   name = config.getSimpleNameProxy("launch.foo.bar.launch");
   assertEquals("Did not get expected name: 'launch.foo.bar'", "launch.foo.bar", name);
   // filenames without the ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION extension
   name = config.getSimpleNameProxy("launch");
   assertEquals("Did not get expected name: 'launch'", "launch", name);
   name = config.getSimpleNameProxy("launch.foo");
   assertEquals("Did not get expected name: 'launch.foo'", "launch.foo", name);
   name = config.getSimpleNameProxy("launch.foo.bar");
   assertEquals("Did not get expected name: 'launch.foo.bar'", "launch.foo.bar", name);
 }
 @Test
 public void testGetPropertyAsBooleanMissing() {
   final Configuration configuration = TestConfiguration.create();
   final Optional<Boolean> value = configuration.getPropertyAsBoolean("foo");
   Assert.assertFalse(value.isPresent());
 }
 @Test(expected = IllegalArgumentException.class)
 public void testGetRequiredAsInvalid() {
   final Configuration configuration = TestConfiguration.create();
   configuration.getRequiredAs(String.class);
 }
 @Test(expected = NoSuchElementException.class)
 public void testGetRequiredPropertyAsBooleanMissing() {
   TestConfiguration.create().getRequiredPropertyAsBoolean("foo");
 }
 @Test
 public void testGetRequiredPropertyAsBooleanExists() {
   final Configuration configuration = TestConfiguration.create("foo", "false");
   final boolean value = configuration.getRequiredPropertyAsBoolean("foo");
   Assert.assertFalse(value);
 }
 @Test
 public void testGetPropertyAsBooleanWithDefaultMissing() {
   final Configuration configuration = TestConfiguration.create();
   final boolean value = configuration.getPropertyAsBoolean("foo", true);
   Assert.assertTrue(value);
 }
 @Test
 public void testGetPropertyAsBooleanWithDefaultExists() {
   final Configuration configuration = TestConfiguration.create("foo", "false");
   final boolean value = configuration.getPropertyAsBoolean("foo", true);
   Assert.assertFalse(value);
 }