1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.services.ssm; 17 18 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertFalse; 20 import static org.junit.Assert.assertNotNull; 21 22 import org.junit.AfterClass; 23 import org.junit.Test; 24 import org.slf4j.Logger; 25 import org.slf4j.LoggerFactory; 26 import software.amazon.awssdk.services.ssm.model.CreateDocumentRequest; 27 import software.amazon.awssdk.services.ssm.model.CreateDocumentResponse; 28 import software.amazon.awssdk.services.ssm.model.DeleteDocumentRequest; 29 import software.amazon.awssdk.services.ssm.model.DescribeDocumentRequest; 30 import software.amazon.awssdk.services.ssm.model.DescribeDocumentResponse; 31 import software.amazon.awssdk.services.ssm.model.DocumentDescription; 32 import software.amazon.awssdk.services.ssm.model.GetDocumentRequest; 33 import software.amazon.awssdk.services.ssm.model.GetDocumentResponse; 34 import software.amazon.awssdk.services.ssm.model.ListDocumentsRequest; 35 import software.amazon.awssdk.services.ssm.model.ListDocumentsResponse; 36 import software.amazon.awssdk.utils.IoUtils; 37 38 public class SSMServiceIntegrationTest extends IntegrationTestBase { 39 40 private static final Logger log = LoggerFactory.getLogger(SSMServiceIntegrationTest.class); 41 private static final String DOCUMENT_LOCATION = "documentContent.json"; 42 private static final String DOCUMENT_NAME = "my-document-" + System.currentTimeMillis(); 43 44 @AfterClass tearDown()45 public static void tearDown() { 46 try { 47 ssm.deleteDocument(DeleteDocumentRequest.builder().name(DOCUMENT_NAME).build()); 48 } catch (Exception e) { 49 log.error("Failed to delete config document.", e); 50 } 51 } 52 53 @Test testAll()54 public void testAll() throws Exception { 55 56 String documentContent = IoUtils.toUtf8String(getClass().getResourceAsStream(DOCUMENT_LOCATION)); 57 testCreateDocument(DOCUMENT_NAME, documentContent); 58 testDescribeDocument(); 59 } 60 testDescribeDocument()61 private void testDescribeDocument() { 62 DescribeDocumentResponse result = ssm.describeDocument(DescribeDocumentRequest.builder().name(DOCUMENT_NAME).build()); 63 assertNotNull(result.document()); 64 } 65 testCreateDocument(String docName, String docContent)66 private void testCreateDocument(String docName, String docContent) { 67 68 CreateDocumentResponse createResult = ssm 69 .createDocument(CreateDocumentRequest.builder().name(docName).content(docContent).build()); 70 71 DocumentDescription description = createResult.documentDescription(); 72 73 assertEquals(docName, description.name()); 74 assertNotNull(description.status()); 75 assertNotNull(description.createdDate()); 76 77 GetDocumentResponse getResult = ssm.getDocument(GetDocumentRequest.builder().name(docName).build()); 78 79 assertEquals(DOCUMENT_NAME, getResult.name()); 80 assertEquals(docContent, getResult.content()); 81 82 ListDocumentsResponse listResult = ssm.listDocuments(ListDocumentsRequest.builder().build()); 83 84 assertFalse("ListDocuments should at least returns one element", listResult.documentIdentifiers().isEmpty()); 85 86 } 87 88 } 89