diff --git a/shopping-cart-v2/Jenkinsfile b/shopping-cart-v2/Jenkinsfile new file mode 100644 index 000000000..8ab2eaea9 --- /dev/null +++ b/shopping-cart-v2/Jenkinsfile @@ -0,0 +1,46 @@ +pipeline { + agent { node { label 'maven' } } + environment { APP_NAMESPACE = 'ebomqy-recover' } + stages { + stage('Test') { + //options { timeout(time: 50, unit: 'SECONDS') } + steps { + dir('shopping-cart-v2') { + sh './mvnw clean test' + } + } + } + stage('Build Image') { + environment { QUAY = credentials('QUAY_USER') } + steps { + dir('shopping-cart-v2') { + sh './scripts/include-container-extensions.sh' + sh ''' + ./scripts/build-and-push-image.sh \ + -u $QUAY_USR \ + -p $QUAY_PSW \ + -b $BUILD_NUMBER + ''' + } + } + } + stage('Deploy') { + environment { QUAY = credentials('QUAY_USER') } + steps { + dir('shopping-cart-v2') { + script { + def status = sh( + script: "./scripts/tag-exists-in-quay.sh $QUAY_USR/do400-recover latest", + returnStatus: true + ) + if (status != 0) { + error("Tag not found in Quay!") + } + } + sh './scripts/redeploy.sh $APP_NAMESPACE' + } + } + } + + } +} \ No newline at end of file diff --git a/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/blackbox/ShoppingCartTest.java b/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/blackbox/ShoppingCartTest.java index 2ed91748c..7bcb4a27b 100644 --- a/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/blackbox/ShoppingCartTest.java +++ b/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/blackbox/ShoppingCartTest.java @@ -21,6 +21,20 @@ @QuarkusTest @Tag("integration") public class ShoppingCartTest { + + @BeforeAll + public static void setup() { + CatalogStorage mockStorage = Mockito.mock(InMemoryCatalogStorage.class); + + Mockito.when(mockStorage.containsKey(1)).thenReturn(true); + Mockito.when(mockStorage.containsKey(2)).thenReturn(true); + Mockito.when(mockStorage.containsKey(9999)).thenReturn(false); + + Mockito.when(mockStorage.get(1)).thenReturn(new Product(1, 100)); + Mockito.when(mockStorage.get(2)).thenReturn(new Product(2, 200)); + + QuarkusMock.installMockForType(mockStorage, CatalogStorage.class); + } private int randomQuantity() { return (new Random()).nextInt(10) + 1; diff --git a/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/whitebox/ShoppingCartTest.java b/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/whitebox/ShoppingCartTest.java index d1eddb753..62872c4bd 100644 --- a/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/whitebox/ShoppingCartTest.java +++ b/shopping-cart-v2/src/test/java/com/redhat/shopping/integration/whitebox/ShoppingCartTest.java @@ -24,6 +24,18 @@ public class ShoppingCartTest { @Inject CartService cartService; + + @BeforeAll + public static void setup() { + CatalogStorage mockStorage = Mockito.mock(InMemoryCatalogStorage.class); + + Mockito.when(mockStorage.containsKey(1)).thenReturn(true); + Mockito.when(mockStorage.containsKey(9999)).thenReturn(false); + + Mockito.when(mockStorage.get(1)).thenReturn(new Product(1, 100)); + + QuarkusMock.installMockForType(mockStorage, CatalogStorage.class); + } @BeforeEach void clearCart() {