Package org.shredzone.acme4j.toolbox
Class TestUtils
java.lang.Object
org.shredzone.acme4j.toolbox.TestUtils
Some utility methods for unit tests.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final NetworkSettings
static final String
static final String
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<X509Certificate>
createCertificate
(String resource) Creates a standard certificate chain for testing.static KeyPair
Creates a standard domain key pair for testing.static KeyPair
createECKeyPair
(String name) Creates a random ECC key pair with the given curve name.static KeyPair
Creates a standard accountKeyPair
for testing.static Problem
createProblem
(URI type, String detail, URL instance) Creates aProblem
with the given type and details.static SecretKey
createSecretKey
(String algorithm) Creates a HMAC key using the given hash algorithm.static JSON
Reads a JSON string from json test files and parses it.static byte[]
getResourceAsByteArray
(String name) Reads a resource as byte array.static Login
login()
Creates aLogin
instance.static void
Generates a new keypair for unit tests, and return its N, E, KTY and THUMBPRINT parameters to be set in theTestUtils
class.static Session
session()
Creates aSession
instance.static Session
session
(AcmeProvider provider) Creates aSession
instance.static URL
Creates anURL
from a String.
-
Field Details
-
N
- See Also:
-
E
- See Also:
-
KTY
- See Also:
-
THUMBPRINT
- See Also:
-
D_N
- See Also:
-
D_E
- See Also:
-
D_KTY
- See Also:
-
D_THUMBPRINT
- See Also:
-
ACME_SERVER_URI
- See Also:
-
ACCOUNT_URL
- See Also:
-
DUMMY_NONCE
-
CERT_ISSUER
- See Also:
-
DEFAULT_NETWORK_SETTINGS
-
-
Method Details
-
getResourceAsByteArray
Reads a resource as byte array.- Parameters:
name
- Resource name- Returns:
- Resource content as byte array.
- Throws:
IOException
-
getJSON
Reads a JSON string from json test files and parses it.- Parameters:
key
- JSON resource- Returns:
- Parsed JSON resource
-
session
Creates aSession
instance. It usesACME_SERVER_URI
as server URI. -
login
Creates aLogin
instance. It usesACME_SERVER_URI
as server URI,ACCOUNT_URL
as account URL, and a random key pair. -
url
Creates anURL
from a String. Only throws a runtime exception if the URL is malformed.- Parameters:
url
- URL to use- Returns:
URL
object
-
session
Creates aSession
instance. It usesACME_SERVER_URI
as server URI.- Parameters:
provider
-AcmeProvider
to be used in this session
-
createKeyPair
Creates a standard accountKeyPair
for testing. The key pair is read from a test resource and is guaranteed not to change between test runs.The constants
N
,E
,KTY
andTHUMBPRINT
are related to the returned key pair and can be used for asserting results.- Returns:
KeyPair
for testing- Throws:
IOException
-
createDomainKeyPair
Creates a standard domain key pair for testing. This keypair is read from a test resource and is guaranteed not to change between test runs.The constants
D_N
,D_E
,D_KTY
andD_THUMBPRINT
are related to the returned key pair and can be used for asserting results.- Returns:
KeyPair
for testing- Throws:
IOException
-
createECKeyPair
Creates a random ECC key pair with the given curve name.- Parameters:
name
- Curve name- Returns:
KeyPair
for testing- Throws:
IOException
-
createSecretKey
Creates a HMAC key using the given hash algorithm.- Parameters:
algorithm
- Name of the hash algorithm to be used- Returns:
SecretKey
for testing- Throws:
IOException
-
createCertificate
Creates a standard certificate chain for testing. This certificate is read from a test resource and is guaranteed not to change between test runs.- Parameters:
resource
- Name of the resource- Returns:
- List of
X509Certificate
for testing - Throws:
IOException
-
createProblem
Creates aProblem
with the given type and details.- Parameters:
type
- Problem typedetail
- Problem detailsinstance
- Instance, ornull
- Returns:
- Created
Problem
object
-
main
Generates a new keypair for unit tests, and return its N, E, KTY and THUMBPRINT parameters to be set in theTestUtils
class.- Throws:
Exception
-