Untitled

 avatar
unknown
plain_text
6 months ago
2.5 kB
5
Indexable
@Test(dependsOnMethods = "testFaqQueryAfterDelete")
public void testFaqCreateSucceeds_idempotent() {
    // Ensure that required objects are not null
    assertNotNull(clientAdapter, "clientAdapter is null");
    assertNotNull(s3Adapter, "s3Adapter is null");
    assertNotNull(faqBucket, "faqBucket is null");
    assertNotNull(indexId, "indexId is null");
    assertNotNull(iamRoleArn, "iamRoleArn is null");

    // Call CreateFaq first time
    String faqName = format("idempotent-faq-%s", UUID.randomUUID().toString());
    String clientToken = "testClientToken" + UUID.randomUUID().toString();
    final String faqFileLocalPath = FAQ_TEST_FILES_PATH_PREFIX + "faqTestData_0.csv";
    final String faqFileS3Path = format("faq-data/faq%s_%s.csv", 0, UUID.randomUUID().toString());

    // Check if paths or S3Info are null before calling uploadFile
    if (faqFileS3Path != null && faqFileLocalPath != null) {
        s3Adapter.uploadFile(S3Info.builder().bucket(faqBucket).prefix(faqFileS3Path).build(), faqFileLocalPath);
    } else {
        fail("FAQ file paths are null");
    }

    // Null check for FAQ creation
    String faqId = this.clientAdapter.createFaqWithClientToken(faqFileS3Path, faqBucket, indexId, faqName, iamRoleArn, clientToken);
    assertThat(faqId).isNotNull();

    // Call CreateFaq with same request again and ensure that response is the same
    String newFaqId = this.clientAdapter.createFaqWithClientToken(faqFileS3Path, faqBucket, indexId, faqName, iamRoleArn, clientToken);
    assertThat(newFaqId).isNotNull();
    assertThat(newFaqId).isEqualTo(faqId);

    // Handle ConflictException scenarios properly
    try {
        String newClientToken = clientToken + "New";
        this.clientAdapter.createFaqWithClientToken(faqFileS3Path, faqBucket, indexId, faqName, iamRoleArn, newClientToken);
    } catch (ConflictException ex) {
        log.info("Expected ConflictException for same request with different token.");
    } catch (Exception ex) {
        fail("Unexpected exception: " + ex.getMessage());
    }

    // Handle ConflictException for same ClientToken and different request
    try {
        String newFaqName = faqName + "new";
        this.clientAdapter.createFaqWithClientToken(faqFileS3Path, faqBucket, indexId, newFaqName, iamRoleArn, clientToken);
    } catch (ConflictException ex) {
        log.info("Expected ConflictException for same client token with different request.");
    } catch (Exception ex) {
        fail("Unexpected exception: " + ex.getMessage());
    }
}
Editor is loading...
Leave a Comment