package com.kryptnostic.client.tests;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

import com.kryptnostic.kodex.v1.client.KryptnosticClient;
import com.kryptnostic.kodex.v1.exceptions.types.BadRequestException;
import com.kryptnostic.kodex.v1.exceptions.types.ResourceNotFoundException;
import com.kryptnostic.storage.v1.models.Document;

/**
 * Kryptnostic client tests. Primarily testing the functionality of KryptnosticConnection.
 * 
 * @author Nick Hewitt
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = TestConfiguration.class)
public class ClientTests {
    @Inject
    private KryptnosticClient kryptnosticClient;

    @Test
    public void uploadDocumentGetDocumentTest() {
        String document = "lo and behold.";
        String id = null;
        try {
            id = kryptnosticClient.uploadDocument(document);
        } catch (BadRequestException e) {
            e.printStackTrace();
        }
        Document retrieved = null;
        try {
            retrieved = kryptnosticClient.getDocument(id);
        } catch (ResourceNotFoundException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(retrieved);
        Assert.assertEquals(retrieved.getBody(), document);
    }

    @Test
    public void updateDocumentTest() {
        String document = "what is best in life? the wind in your hair. falcons at your wrist.";
        String id = null;
        try {
            id = kryptnosticClient.uploadDocument(document);
        } catch (BadRequestException e) {
            e.printStackTrace();
        }
        String newDocument = "what is best in life? To crush your enemies, see them driven before you, and to hear the lamentation of the loved ones.";
        try {
            kryptnosticClient.updateDocument(id, newDocument);
        } catch (ResourceNotFoundException e1) {
            e1.printStackTrace();
        }

        Document retrieved = null;
        try {
            retrieved = kryptnosticClient.getDocument(id);
        } catch (ResourceNotFoundException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(retrieved);
        Assert.assertEquals(retrieved, newDocument);
    }
}

package com.kryptnostic.client.tests;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

import com.kryptnostic.kodex.v1.client.KryptnosticClient;
import com.kryptnostic.kodex.v1.exceptions.types.BadRequestException;
import com.kryptnostic.kodex.v1.exceptions.types.ResourceNotFoundException;
import com.kryptnostic.storage.v1.models.Document;

/**
 * Kryptnostic client tests. Primarily testing the functionality of KryptnosticConnection.
 * 
 * @author Nick Hewitt
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = TestConfiguration.class)
public class ClientTests {
    @Inject
    private KryptnosticClient kryptnosticClient;

    @Test
    public void uploadDocumentGetDocumentTest() {
        String document = "lo and behold.";
        String id = null;
        try {
            id = kryptnosticClient.uploadDocument(document);
        } catch (BadRequestException e) {
            e.printStackTrace();
        }
        Document retrieved = null;
        try {
            retrieved = kryptnosticClient.getDocument(id);
        } catch (ResourceNotFoundException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(retrieved);
        Assert.assertEquals(document, retrieved.getBody());
    }

    @Test
    public void updateDocumentTest() {
        String document = "what is best in life? the wind in your hair. falcons at your wrist.";
        String id = null;
        try {
            id = kryptnosticClient.uploadDocument(document);
        } catch (BadRequestException e) {
            e.printStackTrace();
        }
        String newDocument = "what is best in life? To crush your enemies, see them driven before you, and to hear the lamentation of the loved ones.";
        try {
            kryptnosticClient.updateDocument(id, newDocument);
        } catch (ResourceNotFoundException e1) {
            e1.printStackTrace();
        }

        Document retrieved = null;
        try {
            retrieved = kryptnosticClient.getDocument(id);
        } catch (ResourceNotFoundException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(retrieved);
        Assert.assertEquals(newDocument, retrieved.getBody());
    }
}

fix failing document test