package org.sagebionetworks.upload.discussion;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.test.util.ReflectionTestUtils;

import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.PutObjectRequest;

public class UploadContentToS3DAOImplTest {

	@Mock
	private AmazonS3Client mockS3Client;
	private String bucketName = "bucket";
	private UploadContentToS3DAOImpl dao;

	@Before
	public void before() {
		MockitoAnnotations.initMocks(this);

		dao = new UploadContentToS3DAOImpl();
		ReflectionTestUtils.setField(dao, "s3Client", mockS3Client);
		ReflectionTestUtils.setField(dao, "bucketName", bucketName);
	}

	@Test
	public void testUploadDiscussionContent() throws Exception {
		String content = "this is a message";
		String forumId = "1";
		String threadId = "2";
		String key = dao.uploadDiscussionContent(content, forumId, threadId);
		Mockito.verify(mockS3Client).putObject((PutObjectRequest) Mockito.any());
		assertNotNull(key);
		String[] parts = key.split("/");
		assertTrue(parts.length == 3);
		assertEquals(parts[0], forumId);
		assertEquals(parts[1], threadId);
	}
}

@@ -424,16 +424,87 @@
 Client;%0A
+import com.amazonaws.services.s3.model.BucketCrossOriginConfiguration;%0A
 import c
@@ -1033,16 +1033,238 @@
 ption %7B%0A
+%09%09dao.initialize();%0A%09%09Mockito.verify(mockS3Client).createBucket(Mockito.anyString());%0A%09%09Mockito.verify(mockS3Client).setBucketCrossOriginConfiguration(Mockito.anyString(), (BucketCrossOriginConfiguration) Mockito.any());%0A%0A
 %09%09String

update mock test