Search in sources :

Example 11 with NotFoundException

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

the class AssistantServiceIT method testListCounterexamples.

/**
 * Test listCounterexamples.
 */
@Test
public void testListCounterexamples() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    try {
        ListCounterexamplesOptions listOptions = new ListCounterexamplesOptions.Builder(workspaceId).build();
        CounterexampleCollection ccResponse = service.listCounterexamples(listOptions).execute();
        assertNotNull(ccResponse);
        assertNotNull(ccResponse.getCounterexamples());
        assertNotNull(ccResponse.getPagination());
        assertNotNull(ccResponse.getPagination().getRefreshUrl());
        // nextUrl may be null
        Date start = new Date();
        // Now add a counterexample and make sure we get it back
        CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.createCounterexample(createOptions).execute();
        long count = ccResponse.getCounterexamples().size();
        CounterexampleCollection ccResponse2 = service.listCounterexamples(listOptions.newBuilder().pageLimit(count + 1).includeAudit(true).build()).execute();
        assertNotNull(ccResponse2);
        assertNotNull(ccResponse2.getCounterexamples());
        List<Counterexample> counterexamples = ccResponse2.getCounterexamples();
        assertTrue(counterexamples.size() > count);
        Counterexample exResponse = null;
        for (Counterexample resp : counterexamples) {
            if (resp.getText().equals(counterExampleText)) {
                exResponse = resp;
                break;
            }
        }
        assertNotNull(exResponse);
        Date now = new Date();
        assertTrue(fuzzyBefore(exResponse.getCreated(), now));
        assertTrue(fuzzyAfter(exResponse.getCreated(), start));
        assertTrue(fuzzyBefore(exResponse.getUpdated(), now));
        assertTrue(fuzzyAfter(exResponse.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        try {
            DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
            service.deleteCounterexample(deleteOptions).execute();
        } catch (NotFoundException ex) {
        // Okay
        }
    }
}
Also used : ListCounterexamplesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListCounterexamplesOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions) Counterexample(com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample) CreateCounterexample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) CounterexampleCollection(com.ibm.watson.developer_cloud.assistant.v1.model.CounterexampleCollection) CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) Test(org.junit.Test)

Example 12 with NotFoundException

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

the class ConversationServiceIT method testDeleteCounterexample.

/**
 * Test deleteCounterexample.
 */
@Test
public void testDeleteCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.deleteCounterexample(deleteOptions).execute();
    try {
        GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.getCounterexample(getOptions).execute();
        fail("deleteCounterexample failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions) GetCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 13 with NotFoundException

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

the class ErrorResponseTest method testNotFound.

/**
 * Test HTTP status code 404 (NotFound) error response.
 */
@Test
public void testNotFound() {
    String message = "The request failed because the moon is full.";
    server.enqueue(new MockResponse().setResponseCode(404).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
    try {
        GenericModel response = service.testMethod().execute();
    } catch (Exception e) {
        assertTrue(e instanceof NotFoundException);
        NotFoundException ex = (NotFoundException) e;
        assertEquals(404, ex.getStatusCode());
        assertEquals(message, ex.getMessage());
    }
}
Also used : GenericModel(com.ibm.watson.developer_cloud.service.model.GenericModel) MockResponse(okhttp3.mockwebserver.MockResponse) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) BadRequestException(com.ibm.watson.developer_cloud.service.exception.BadRequestException) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) UnsupportedException(com.ibm.watson.developer_cloud.service.exception.UnsupportedException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) InternalServerErrorException(com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException) ServiceUnavailableException(com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 14 with NotFoundException

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

the class NaturalLanguageClassifierIT method bGetClassifier.

/**
 * Test get classifier.
 */
@Test
public void bGetClassifier() {
    final Classifier classifier;
    try {
        GetClassifierOptions getOptions = new GetClassifierOptions.Builder().classifierId(classifierId).build();
        classifier = service.getClassifier(getOptions).execute();
    } catch (NotFoundException e) {
        // The build should not fail here, because this is out of our control.
        throw new AssumptionViolatedException(e.getMessage(), e);
    }
    assertNotNull(classifier);
    assertEquals(classifierId, classifier.getClassifierId());
    assertEquals(Classifier.Status.TRAINING, classifier.getStatus());
}
Also used : GetClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.GetClassifierOptions) AssumptionViolatedException(org.junit.AssumptionViolatedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Classifier(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 15 with NotFoundException

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

the class AssistantServiceIT method testDeleteWorkspace.

/**
 * Test deleteWorkspace.
 */
@Test
public void testDeleteWorkspace() {
    CreateWorkspaceOptions createOptions = new CreateWorkspaceOptions.Builder().build();
    String workspaceId = null;
    try {
        Workspace response = service.createWorkspace(createOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getWorkspaceId());
        workspaceId = response.getWorkspaceId();
        DeleteWorkspaceOptions deleteOptions = new DeleteWorkspaceOptions.Builder(workspaceId).build();
        service.deleteWorkspace(deleteOptions).execute();
        GetWorkspaceOptions getOptions = new GetWorkspaceOptions.Builder(workspaceId).export(true).build();
        service.getWorkspace(getOptions).execute();
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
        workspaceId = null;
    } finally {
        // Clean up
        if (workspaceId != null) {
            DeleteWorkspaceOptions deleteOptions = new DeleteWorkspaceOptions.Builder(workspaceId).build();
            service.deleteWorkspace(deleteOptions).execute();
        }
    }
}
Also used : DeleteWorkspaceOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteWorkspaceOptions) CreateWorkspaceOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions) 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) Workspace(com.ibm.watson.developer_cloud.assistant.v1.model.Workspace) GetWorkspaceOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetWorkspaceOptions) 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