Search in sources :

Example 1 with NotFoundException

use of com.ibm.watson.developer_cloud.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifierIT method dClassify.

/**
 * Test classify. Use the pre created classifier to avoid waiting for availability
 */
@Test
public void dClassify() {
    Classification classification = null;
    try {
        ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId(preCreatedClassifierId).text("is it hot outside?").build();
        classification = service.classify(classifyOptions).execute();
    } catch (NotFoundException e) {
        // The build should not fail here, because this is out of our control.
        throw new AssumptionViolatedException(e.getMessage(), e);
    }
    assertNotNull(classification);
    assertEquals("temperature", classification.getTopClass());
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Classification(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification) ClassifyOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with NotFoundException

use of com.ibm.watson.developer_cloud.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifierIT method fClassifyCollection.

/**
 * Test classifyCollection. Use the pre created classifier to avoid waiting for availability
 */
@Test
public void fClassifyCollection() {
    ClassificationCollection classificationCollection = null;
    ClassifyInput input1 = new ClassifyInput();
    input1.setText("How hot will it be today?");
    ClassifyInput input2 = new ClassifyInput();
    input2.setText("Is it hot outside?");
    try {
        ClassifyCollectionOptions classifyOptions = new ClassifyCollectionOptions.Builder().classifierId(preCreatedClassifierId).addClassifyInput(input1).addClassifyInput(input2).build();
        classificationCollection = service.classifyCollection(classifyOptions).execute();
    } catch (NotFoundException e) {
        // The build should not fail here, because this is out of our control.
        throw new AssumptionViolatedException(e.getMessage(), e);
    }
    assertNotNull(classificationCollection);
    assertEquals("temperature", classificationCollection.getCollection().get(0).getTopClass());
    assertEquals("temperature", classificationCollection.getCollection().get(1).getTopClass());
}
Also used : ClassificationCollection(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection) ClassifyCollectionOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyCollectionOptions) AssumptionViolatedException(org.junit.AssumptionViolatedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ClassifyInput(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyInput) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with NotFoundException

use of com.ibm.watson.developer_cloud.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.

the class ConversationServiceIT method testDeleteExample.

/**
 * Test deleteExample.
 */
@Test
public void testDeleteExample() {
    createExampleIntent();
    // gotta be unique
    String exampleText = "Howdy " + UUID.randomUUID().toString();
    CreateExampleOptions createOptions = new CreateExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.createExample(createOptions).execute();
    DeleteExampleOptions deleteOptions = new DeleteExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
    service.deleteExample(deleteOptions).execute();
    try {
        GetExampleOptions getOptions = new GetExampleOptions.Builder(workspaceId, exampleIntent, exampleText).build();
        service.getExample(getOptions).execute();
        fail("deleteCounterexample failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateExampleOptions) GetExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetExampleOptions) DeleteExampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteExampleOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 4 with NotFoundException

use of com.ibm.watson.developer_cloud.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.

the class ConversationServiceIT method testDeleteIntent.

/**
 * Test deleteIntent.
 */
@Test
public void testDeleteIntent() {
    // gotta be unique
    String intentName = "Hello" + UUID.randomUUID().toString();
    CreateIntentOptions createOptions = new CreateIntentOptions.Builder(workspaceId, intentName).build();
    service.createIntent(createOptions).execute();
    DeleteIntentOptions deleteOptions = new DeleteIntentOptions.Builder(workspaceId, intentName).build();
    service.deleteIntent(deleteOptions).execute();
    try {
        GetIntentOptions getOptions = new GetIntentOptions.Builder(workspaceId, intentName).build();
        service.getIntent(getOptions).execute();
        fail("deleteIntent failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateIntentOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateIntentOptions) DeleteIntentOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteIntentOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) GetIntentOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetIntentOptions) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 5 with NotFoundException

use of com.ibm.watson.developer_cloud.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.

the class ValuesIT method testDeleteValue.

/**
 * Test deleteValue.
 */
@Test
public void testDeleteValue() {
    String entity = "beverage";
    String entityValue = "coffee" + UUID.randomUUID().toString();
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
    Value response = service.createValue(createOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getValueText());
        assertEquals(response.getValueText(), entityValue);
        assertNull(response.getMetadata());
    } catch (Exception ex) {
        // Clean up
        DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.deleteValue(deleteOptions).execute();
        fail(ex.getMessage());
    }
    DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).build();
    service.deleteValue(deleteOptions).execute();
    try {
        GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.getValue(getOptions).execute();
        fail("deleteValue failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : GetValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetValueOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) DeleteValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteValueOptions) CreateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions) Value(com.ibm.watson.developer_cloud.conversation.v1.model.Value) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)22 Test (org.junit.Test)22 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)13 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)3 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)3 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions)2 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)2 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions)2 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions)2 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)2 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)1 CounterexampleCollection (com.ibm.watson.developer_cloud.assistant.v1.model.CounterexampleCollection)1 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)1 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions)1 CreateExampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExampleOptions)1 CreateIntentOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateIntentOptions)1