Spring Boot and Jasypt Code (#4142)
* Spring Boot and Jasypt Code * Tabs to Spaces in POM * Removed unnecessary files * Formatted Pom
This commit is contained in:
committed by
pauljervis
parent
a9f08084ff
commit
1e3b3f27a4
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.jasypt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.jasypt.Main;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {Main.class})
|
||||
public class CustomJasyptTest {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext appCtx;
|
||||
|
||||
@Test
|
||||
public void whenConfiguredExcryptorUsed_ReturnCustomEncryptor() {
|
||||
Environment environment = appCtx.getBean(Environment.class);
|
||||
assertEquals("Password@3", environment.getProperty("encryptedv3.property"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.jasypt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.jasypt.simple.PropertyServiceForJasyptSimple;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class JasyptSimpleTest {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext appCtx;
|
||||
|
||||
@Test
|
||||
public void whenDecryptedPasswordNeeded_GetFromService() {
|
||||
System.setProperty("jasypt.encryptor.password", "password");
|
||||
PropertyServiceForJasyptSimple service = appCtx.getBean(PropertyServiceForJasyptSimple.class);
|
||||
assertEquals("Password@2", service.getProperty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.jasypt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.jasypt.starter.PropertyServiceForJasyptStarter;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class JasyptWithStarterTest {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext appCtx;
|
||||
|
||||
@Test
|
||||
public void whenDecryptedPasswordNeeded_GetFromService() {
|
||||
System.setProperty("jasypt.encryptor.password", "password");
|
||||
PropertyServiceForJasyptStarter service = appCtx.getBean(PropertyServiceForJasyptStarter.class);
|
||||
assertEquals("Password@1", service.getProperty());
|
||||
Environment environment = appCtx.getBean(Environment.class);
|
||||
assertEquals("Password@1", service.getPasswordUsingEnvironment(environment));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user