forked from aws/aws-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAWSTestBase.java
More file actions
174 lines (154 loc) · 6.01 KB
/
AWSTestBase.java
File metadata and controls
174 lines (154 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.test;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.PropertiesFileCredentialsProvider;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.test.util.InputStreamUtils;
import com.amazonaws.test.util.SdkAsserts;
import com.amazonaws.util.IOUtils;
public abstract class AWSTestBase {
/**
* Shared AWS credentials, loaded from a properties file. Direct access to this field is
* deprecated
*
* @deprecated Extend from {@link AWSIntegrationTestBase} to access credentials
*/
@Deprecated
public static AWSCredentials credentials;
/** Default Properties Credentials file path */
private static final String propertiesFilePath = System.getProperty("user.home")
+ "/.aws/awsTestAccount.properties";
private static final String TEST_CREDENTIALS_PROFILE_NAME = "aws-java-sdk-test";
private static final AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
new PropertiesFileCredentialsProvider(propertiesFilePath),
new ProfileCredentialsProvider(TEST_CREDENTIALS_PROFILE_NAME), new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider());
/**
* @deprecated Extend from {@link AWSIntegrationTestBase} to access credentials
*/
@Deprecated
public static void setUpCredentials() {
if (credentials == null) {
try {
credentials = chain.getCredentials();
} catch (Exception ignored) {
}
}
}
/**
* Reads a system resource fully into a String
*
* @param location
* Relative or absolute location of system resource.
* @return String contents of resource file
* @throws RuntimeException
* if any error occurs
*/
protected String getResourceAsString(String location) {
try {
InputStream resourceStream = getClass().getResourceAsStream(location);
String resourceAsString = IOUtils.toString(resourceStream);
resourceStream.close();
return resourceAsString;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertNotEmpty(String str) {
SdkAsserts.assertNotEmpty(str);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertFileEqualsStream(File expected, InputStream actual) {
SdkAsserts.assertFileEqualsStream(expected, actual);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertFileEqualsStream(String errmsg, File expected, InputStream actual) {
SdkAsserts.assertFileEqualsStream(errmsg, expected, actual);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertStreamEqualsStream(InputStream expected, InputStream actual) {
SdkAsserts.assertStreamEqualsStream(expected, actual);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertStreamEqualsStream(String errmsg, InputStream expectedInputStream, InputStream inputStream) {
assertStreamEqualsStream(errmsg, expectedInputStream, inputStream);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertFileEqualsFile(File expected, File actual) {
SdkAsserts.assertFileEqualsFile(expected, actual);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertStringEqualsStream(String expected, InputStream actual) {
SdkAsserts.assertStringEqualsStream(expected, actual);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected boolean doesStreamEqualStream(InputStream expected, InputStream actual) throws IOException {
return SdkAsserts.doesStreamEqualStream(expected, actual);
}
/**
* @deprecated Use {@link InputStreamUtils#drainInputStream(InputStream)}
*/
@Deprecated
protected byte[] drainInputStream(InputStream inputStream) {
return InputStreamUtils.drainInputStream(inputStream);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected boolean doesFileEqualStream(File expectedFile, InputStream inputStream) throws IOException {
return SdkAsserts.doesFileEqualStream(expectedFile, inputStream);
}
/**
* @deprecated Use static imports for custom asserts in {@link SdkAsserts} instead
*/
@Deprecated
protected void assertValidException(AmazonServiceException e) {
SdkAsserts.assertValidException(e);
}
}