Example #1
0
  @BeforeClass(groups = {"wso2.greg.resource"})
  public void init() throws Exception {
    log.info("Initializing Tests for Community Feature in Registry Policy");
    log.debug("Community Feature in Registry Policy Test Initialised");
    loggedInSessionCookie = util.login();
    frameworkPath = FrameworkSettings.getFrameworkPath();

    log.debug("Running SuccessCase");
    resourceAdminServiceStub = TestUtils.getResourceAdminServiceStub(loggedInSessionCookie);
    contentSearchAdminServiceStub =
        TestUtils.getContentSearchAdminServiceStub(loggedInSessionCookie);
  }
  /** Validate simple statement selects for all primitive data types */
  public void primitiveSelectTest() throws Throwable {
    String execute_string;
    Object value;
    Row row;
    for (DataType dataType : PRIMITIVE_SELECT_STATEMENTS.keySet()) {
      execute_string = PRIMITIVE_SELECT_STATEMENTS.get(dataType);
      row = session.execute(execute_string).one();

      value = SAMPLE_DATA.get(dataType);
      assertEquals(TestUtils.getValue(row, "k", dataType), value);
      assertEquals(TestUtils.getValue(row, "v", dataType), value);
    }
    assertEquals(SAMPLE_DATA.size(), 15);
    assertEquals(PRIMITIVE_SELECT_STATEMENTS.keySet().size(), SAMPLE_DATA.size());
  }
  // The two following tests a really unit tests, but since the whole uses
  // CCMBridge.PerClassSingleNodeCluster, they'll still spawn a cluster even
  // you execute only them, so we keep them in the "long" group. We could
  // move them in another class but not sure where honestly (one could argue
  // that it would make more sense to move all the *other* tests to some
  // DataTypeIntegrationTest class).
  @Test(groups = "long")
  public void serializeDeserializeTest() {

    for (DataType dt : DataType.allPrimitiveTypes()) {
      if (exclude(dt)) continue;

      Object value = TestUtils.getFixedValue(dt);
      assertEquals(dt.deserialize(dt.serialize(value)), value);
    }

    try {
      DataType.bigint().serialize(4);
      fail("This should not have worked");
    } catch (InvalidTypeException e) {
      /* That's what we want */
    }

    try {
      ByteBuffer badValue = ByteBuffer.allocate(4);
      DataType.bigint().deserialize(badValue);
      fail("This should not have worked");
    } catch (InvalidTypeException e) {
      /* That's what we want */
    }
  }
  /** Test simple statement selects for all collection data types */
  @SuppressWarnings("unchecked")
  public void collectionSelectTest() throws Throwable {
    HashMap<DataType, Object> sampleValueMap;
    String execute_string;
    DataType typeArgument1;
    DataType typeArgument2;
    Row row;
    for (DataType dataType : COLLECTION_SELECT_STATEMENTS.keySet()) {
      execute_string = COLLECTION_SELECT_STATEMENTS.get(dataType);
      row = session.execute(execute_string).one();

      sampleValueMap = (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);
      typeArgument1 = dataType.getTypeArguments().get(0);
      if (dataType.getName() == DataType.Name.MAP) {
        typeArgument2 = dataType.getTypeArguments().get(1);

        // Create a copy of the map that is being expected
        HashMap<DataType, Object> sampleMap =
            (HashMap<DataType, Object>) sampleValueMap.get(typeArgument1);
        Object mapKey = SAMPLE_DATA.get(sampleMap.keySet().iterator().next());
        Object mapValue = sampleMap.values().iterator().next();
        HashMap<Object, Object> expectedMap = new HashMap<Object, Object>();
        expectedMap.put(mapKey, mapValue);

        assertEquals(TestUtils.getValue(row, "k", typeArgument2), SAMPLE_DATA.get(typeArgument2));
        assertEquals(TestUtils.getValue(row, "v", dataType), expectedMap);
      } else {
        Object expectedValue = sampleValueMap.get(typeArgument1);

        assertEquals(TestUtils.getValue(row, "k", typeArgument1), SAMPLE_DATA.get(typeArgument1));
        assertEquals(TestUtils.getValue(row, "v", dataType), expectedValue);
      }
    }
    assertEquals(SAMPLE_COLLECTIONS.size(), 255);
    assertEquals(COLLECTION_SELECT_STATEMENTS.keySet().size(), SAMPLE_COLLECTIONS.size());
  }
 @Test(dataProvider = "a")
 public void testUniquePathsWithObstacles(String input, int expect) throws Exception {
   int[][] grid = TestUtils.parseIntGrid(input);
   int actual = new Solution63().uniquePathsWithObstacles(grid);
   assertEquals(actual, expect);
 }
 @BeforeClass(alwaysRun = true)
 public void init() throws RegistryException, AxisFault {
   governance = TestUtils.getRegistry();
   registry = TestUtils.getWSRegistry();
   TestUtils.cleanupResources(governance);
 }