package com.cloudbees.jenkins.plugins.awscredentials;

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import hudson.security.ACL;
import io.jenkins.plugins.casc.misc.RoundTripAbstractTest;
import org.jvnet.hudson.test.RestartableJenkinsRule;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assume.assumeThat;

public class ConfigurationAsCodeTest extends RoundTripAbstractTest {

    @Override
    protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
        AWSCredentialsImpl credentials = CredentialsMatchers.firstOrNull(
                CredentialsProvider.lookupCredentials(AWSCredentialsImpl.class,
                        r.j.jenkins, ACL.SYSTEM, (DomainRequirement) null),
                CredentialsMatchers.withId("aws-credentials-casc"));
        assumeThat("AWS credentials are not null", credentials, notNullValue());
        assumeThat("access key is configured", credentials.getAccessKey(),
                equalTo("foo"));
        assumeThat("description is configured", credentials.getDescription(),
                equalTo("foo-description"));
        assumeThat("mfa serial is configured", credentials.getIamMfaSerialNumber(),
                equalTo("arn:aws:iam::123456789012:mfa/user"));
        assumeThat("role arn is configured", credentials.getIamRoleArn(),
                equalTo("arn:aws:iam::123456789012:role/MyIAMRoleName"));
        assumeThat("id is configured", credentials.getId(),
                equalTo("aws-credentials-casc"));
        assumeThat("scope is configured", credentials.getScope(),
                equalTo(CredentialsScope.GLOBAL));
        assumeThat("secret key is configured", credentials.getSecretKey().getPlainText(),
                equalTo("bar"));
    }

    @Override
    protected String stringInLogExpected() {
        return "AWSCredentialsImpl";
    }
}

@@ -462,83 +462,33 @@
 org.
-hamcrest.Matchers.equalTo;%0Aimport static org.hamcrest.Matchers.notNullValue
+junit.Assert.assertEquals
 ;%0Aim
@@ -516,22 +516,25 @@
 .Ass
-ume
+ert
 .ass
-umeThat
+ertNotNull
 ;%0A%0Ap
@@ -1035,125 +1035,54 @@
  ass
-umeThat(%22AWS credentials are not null%22, credentials, notNullValue());%0A        assumeThat(%22access key is configured%22, 
+ertNotNull(credentials);%0A        assertEquals(
 cred
@@ -1108,40 +1108,15 @@
 y(),
-%0A                equalTo(
+ 
 %22foo%22)
-)
 ;%0A  
@@ -1128,45 +1128,18 @@
  ass
-umeThat(%22description is configured%22, 
+ertEquals(
 cred
@@ -1167,33 +1167,9 @@
 n(),
-%0A                equalTo(
+ 
 %22foo
@@ -1182,17 +1182,16 @@
 iption%22)
-)
 ;%0A      
@@ -1199,44 +1199,18 @@
  ass
-umeThat(%22mfa serial is configured%22, 
+ertEquals(
 cred
@@ -1245,33 +1245,9 @@
 r(),
-%0A                equalTo(
+ 
 %22arn
@@ -1279,17 +1279,16 @@
 a/user%22)
-)
 ;%0A      
@@ -1296,42 +1296,18 @@
  ass
-umeThat(%22role arn is configured%22, 
+ertEquals(
 cred
@@ -1334,33 +1334,9 @@
 n(),
-%0A                equalTo(
+ 
 %22arn
@@ -1378,17 +1378,16 @@
 leName%22)
-)
 ;%0A      
@@ -1395,81 +1395,39 @@
  ass
-umeThat(%22id is configured%22, credentials.getId(),%0A                equalTo(
+ertEquals(credentials.getId(), 
 %22aws
@@ -1437,33 +1437,32 @@
 edentials-casc%22)
-)
 ;%0A        assume
@@ -1462,87 +1462,42 @@
  ass
-umeThat(%22scope is configured%22, credentials.getScope(),%0A                equalTo(
+ertEquals(credentials.getScope(), 
 Cred
@@ -1516,17 +1516,16 @@
 .GLOBAL)
-)
 ;%0A      
@@ -1533,44 +1533,18 @@
  ass
-umeThat(%22secret key is configured%22, 
+ertEquals(
 cred
@@ -1585,40 +1585,15 @@
 t(),
-%0A                equalTo(
+ 
 %22bar%22)
-)
 ;%0A  

replace assume with assert, hehe