예제 #1
0
  public static void main(String[] args) {
    try {
      // step 1 - create a user object for authentication
      User user = new User(Config.username, Config.api_key);
      // step 2 - create a definition
      Definition def =
          user.createDefinition(
              "interaction.type == \"twitter\" and (interaction.content contains \"music\")");
      // step 3 - make the request to have our csdl compiled
      def.compile();
      System.out.println("Hash: " + def.getHash());
      System.out.println("Created at: " + def.getCreatedAt());
      System.out.println("Total cost: " + def.getTotalDPU());

    } catch (Exception ex) {
      System.err.println();
      Logger.getLogger("net.datasift.example")
          .log(Level.WARNING, "An error occured: " + ex.getMessage());
    }
  }
예제 #2
0
  public void testValidate_SuccessThenFailure() {
    Definition def = new Definition(user, DataForTests.definition);
    try {
      assertEquals("Definition string not set correctly", def.get(), DataForTests.definition);
    } catch (EInvalidData e1) {
      fail("EInvalidData: " + e1.getMessage());
    }

    try {
      def.validate();

      // We should now have a hash
      assertEquals("Hash is not correct", def.getHash(), DataForTests.definition_hash);
    } catch (EInvalidData e) {
      fail("InvalidData: " + e.getMessage());
    } catch (ECompileFailed e) {
      fail("CompileFailed: " + e.getMessage());
    } catch (EAccessDenied e) {
      fail("AccessDenied: " + e.getMessage());
    }

    // Now set the invalid definition in that same object
    def.set(DataForTests.invalid_definition);
    try {
      assertEquals(
          "Definition string not set correctly", def.get(), DataForTests.invalid_definition);
    } catch (EInvalidData e1) {
      fail("EInvalidData: " + e1.getMessage());
    }

    try {
      def.compile();
      fail("CompileFailed exception expected, but not thrown");
    } catch (EInvalidData e) {
      fail("InvalidData: " + e.getMessage());
    } catch (ECompileFailed e) {
      // This is what we should get
    } catch (EAccessDenied e) {
      fail("AccessDenied: " + e.getMessage());
    }
  }
예제 #3
0
  public void testValidate_Success() {
    Definition def = new Definition(user, DataForTests.definition);
    try {
      assertEquals("Definition string not set correctly", def.get(), DataForTests.definition);
    } catch (EInvalidData e1) {
      fail("EInvalidData: " + e1.getMessage());
    }

    try {
      def.validate();

      // We should now have a hash
      assertEquals("Incorrect hash", def.getHash(), DataForTests.definition_hash);
    } catch (EInvalidData e) {
      fail("InvalidData: " + e.getMessage());
    } catch (ECompileFailed e) {
      fail("CompileFailed: " + e.getMessage());
    } catch (EAccessDenied e) {
      fail("AccessDenied: " + e.getMessage());
    }
  }