-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Kulasek-Szwed
committed
Nov 18, 2019
1 parent
472b975
commit 4552a45
Showing
8 changed files
with
162 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package pl.hycom.mokka.core; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.stereotype.Service; | ||
import pl.hycom.mokka.security.UserManager; | ||
|
||
/** | ||
|
@@ -18,12 +19,13 @@ | |
* @author Piotr Kulasek-Szwed <[email protected]> | ||
*/ | ||
@Slf4j | ||
@Component | ||
@Service | ||
@RequiredArgsConstructor | ||
public class InitialSetupCommandLineRunner implements CommandLineRunner { | ||
|
||
@Autowired | ||
private UserManager userManager; | ||
private final UserManager userManager; | ||
|
||
@Setter | ||
@Value("${setup.initial.enabled}") | ||
private boolean initialSetupEnabled; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package pl.hycom.mokka; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
/** | ||
* @author Mariusz Krysztofowicz ([email protected]) | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(classes = Application.class) | ||
@AutoConfigureTestDatabase | ||
@TestPropertySource(locations = "classpath:test.properties") | ||
|
61 changes: 61 additions & 0 deletions
61
src/mokka/src/test/java/pl/hycom/mokka/core/InitialSetupCommandLineRunnerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pl.hycom.mokka.core; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import pl.hycom.mokka.security.UserManager; | ||
|
||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Piotr Kulasek-Szwed <[email protected]> | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
public class InitialSetupCommandLineRunnerTest { | ||
|
||
@Mock | ||
private UserManager userManager; | ||
|
||
@InjectMocks | ||
private InitialSetupCommandLineRunner initialSetupCommandLineRunner; | ||
|
||
@Test | ||
public void shouldSkipInitialConfig(){ | ||
// given | ||
when(userManager.numberOfAdmins()).thenReturn(1); | ||
initialSetupCommandLineRunner.setInitialSetupEnabled(true); | ||
|
||
// when | ||
try { | ||
initialSetupCommandLineRunner.run(""); | ||
} catch (Exception e) { | ||
Assertions.fail(); | ||
} | ||
|
||
// then | ||
verify(userManager, atLeastOnce()).numberOfAdmins(); | ||
} | ||
|
||
@Test | ||
public void shouldExecuteInitialConfig(){ | ||
// given | ||
when(userManager.numberOfAdmins()).thenReturn(0); | ||
initialSetupCommandLineRunner.setInitialSetupEnabled(true); | ||
|
||
// when | ||
try { | ||
initialSetupCommandLineRunner.run(""); | ||
} catch (Exception e) { | ||
Assertions.fail(); | ||
} | ||
|
||
// then | ||
verify(userManager, atLeastOnce()).createAdminUser(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 24 additions & 26 deletions
50
src/mokka/src/test/java/pl/hycom/mokka/service/impl/DefaultPaymentStatusServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,49 @@ | ||
package pl.hycom.mokka.service.impl; | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import pl.hycom.mokka.AbstractTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.client.MockRestServiceServer; | ||
import pl.hycom.mokka.service.payment.DefaultPaymentStatusService; | ||
import pl.hycom.mokka.service.payment.pojo.BlueMediaPayment; | ||
import pl.hycom.mokka.service.payment.PaymentStatusService; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; | ||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; | ||
|
||
|
||
/** | ||
* @author Mariusz Krysztofowicz ([email protected]) | ||
*/ | ||
@Ignore | ||
public class DefaultPaymentStatusServiceTest extends AbstractTest { | ||
@Disabled | ||
public class DefaultPaymentStatusServiceTest{ | ||
|
||
@Resource | ||
private PaymentStatusService paymentStatusService; | ||
private DefaultPaymentStatusService defaultPaymentStatusService; | ||
|
||
@Rule | ||
public WireMockRule wireMockRule = new WireMockRule(48080); | ||
@Autowired | ||
private MockRestServiceServer server; | ||
|
||
@Before | ||
@BeforeEach | ||
public void init() { | ||
wireMockRule.stubFor(post(urlPathMatching("/soap/webservice-http/payment")).willReturn(aResponse().withHeader("Content-Type", "text/plain") | ||
.withBody("OK") | ||
.withStatus(200))); | ||
defaultPaymentStatusService = new DefaultPaymentStatusService();//new DefaultHashGenerator()); | ||
this.server.expect(requestTo("/soap/webservice-http/payment")) | ||
.andRespond(withSuccess("OK", MediaType.TEXT_PLAIN)); | ||
} | ||
|
||
@Test | ||
public void TestSuccess() { | ||
paymentStatusService.paymentStatusSuccessUpdate(createSampleBlueMediaPayment()); | ||
public void shouldSendSuccess() { | ||
defaultPaymentStatusService.paymentStatusSuccessUpdate(createSampleBlueMediaPayment()); | ||
} | ||
|
||
@Test | ||
public void TestPending() { | ||
paymentStatusService.paymentStatusPendingUpdate(createSampleBlueMediaPayment()); | ||
public void shouldSendPending() { | ||
defaultPaymentStatusService.paymentStatusPendingUpdate(createSampleBlueMediaPayment()); | ||
} | ||
|
||
@Test | ||
public void TestFailure() { | ||
paymentStatusService.paymentStatusFailureUpdate(createSampleBlueMediaPayment()); | ||
public void shouldSendFailure() { | ||
defaultPaymentStatusService.paymentStatusFailureUpdate(createSampleBlueMediaPayment()); | ||
} | ||
|
||
private BlueMediaPayment createSampleBlueMediaPayment() { | ||
|
Oops, something went wrong.