├── src ├── test │ ├── resources │ │ └── .gitkeep │ └── java │ │ └── org │ │ └── mybatis │ │ └── jpetstore │ │ ├── web │ │ └── actions │ │ │ ├── OrderActionBeanTest.java │ │ │ ├── AccountActionBeanTest.java │ │ │ └── CatalogActionBeanTest.java │ │ ├── mapper │ │ ├── SequenceMapperTest.java │ │ ├── MapperTestContext.java │ │ ├── LineItemMapperTest.java │ │ ├── CategoryMapperTest.java │ │ ├── ProductMapperTest.java │ │ └── ItemMapperTest.java │ │ ├── service │ │ ├── AccountServiceTest.java │ │ └── CatalogServiceTest.java │ │ └── domain │ │ ├── OrderTest.java │ │ └── CartTest.java ├── main │ ├── webapp │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ ├── images │ │ │ ├── cart.gif │ │ │ ├── cat1.gif │ │ │ ├── cat2.gif │ │ │ ├── dog1.gif │ │ │ ├── dog2.gif │ │ │ ├── dog3.gif │ │ │ ├── dog4.gif │ │ │ ├── dog5.gif │ │ │ ├── dog6.gif │ │ │ ├── dogs.gif │ │ │ ├── fish.gif │ │ │ ├── bird1.gif │ │ │ ├── bird2.gif │ │ │ ├── fish1.gif │ │ │ ├── fish2.gif │ │ │ ├── fish3.gif │ │ │ ├── fish4.gif │ │ │ ├── snake1.gif │ │ │ ├── splash.gif │ │ │ ├── cats_icon.gif │ │ │ ├── dogs_icon.gif │ │ │ ├── fish_icon.gif │ │ │ ├── lizard1.gif │ │ │ ├── poweredby.gif │ │ │ ├── separator.gif │ │ │ ├── sm_birds.gif │ │ │ ├── sm_cats.gif │ │ │ ├── sm_dogs.gif │ │ │ ├── sm_fish.gif │ │ │ ├── banner_cats.gif │ │ │ ├── banner_dogs.gif │ │ │ ├── banner_fish.gif │ │ │ ├── birds_icon.gif │ │ │ ├── logo-topbar.gif │ │ │ ├── sm_reptiles.gif │ │ │ ├── banner_birds.gif │ │ │ ├── reptiles_icon.gif │ │ │ └── banner_reptiles.gif │ │ ├── WEB-INF │ │ │ ├── jsp │ │ │ │ ├── common │ │ │ │ │ ├── Error.jsp │ │ │ │ │ ├── IncludeBottom.jsp │ │ │ │ │ └── IncludeTop.jsp │ │ │ │ ├── cart │ │ │ │ │ ├── IncludeMyList.jsp │ │ │ │ │ ├── Checkout.jsp │ │ │ │ │ └── Cart.jsp │ │ │ │ ├── account │ │ │ │ │ ├── SignonForm.jsp │ │ │ │ │ ├── NewAccountForm.jsp │ │ │ │ │ ├── EditAccountForm.jsp │ │ │ │ │ └── IncludeAccountFields.jsp │ │ │ │ ├── order │ │ │ │ │ ├── ListOrders.jsp │ │ │ │ │ ├── ShippingForm.jsp │ │ │ │ │ ├── NewOrderForm.jsp │ │ │ │ │ ├── ConfirmOrder.jsp │ │ │ │ │ └── ViewOrder.jsp │ │ │ │ └── catalog │ │ │ │ │ ├── Category.jsp │ │ │ │ │ ├── SearchProducts.jsp │ │ │ │ │ ├── Item.jsp │ │ │ │ │ ├── Product.jsp │ │ │ │ │ └── Main.jsp │ │ │ ├── web.xml │ │ │ └── applicationContext.xml │ │ └── index.html │ ├── resources │ │ ├── StripesResources.properties │ │ ├── org │ │ │ └── mybatis │ │ │ │ └── jpetstore │ │ │ │ └── mapper │ │ │ │ ├── SequenceMapper.xml │ │ │ │ ├── CategoryMapper.xml │ │ │ │ ├── LineItemMapper.xml │ │ │ │ ├── ProductMapper.xml │ │ │ │ ├── ItemMapper.xml │ │ │ │ ├── OrderMapper.xml │ │ │ │ └── AccountMapper.xml │ │ └── database │ │ │ └── jpetstore-hsqldb-schema.sql │ └── java │ │ └── org │ │ └── mybatis │ │ └── jpetstore │ │ ├── mapper │ │ ├── SequenceMapper.java │ │ ├── CategoryMapper.java │ │ ├── LineItemMapper.java │ │ ├── ProductMapper.java │ │ ├── OrderMapper.java │ │ ├── ItemMapper.java │ │ └── AccountMapper.java │ │ ├── domain │ │ ├── Sequence.java │ │ ├── Category.java │ │ ├── Product.java │ │ ├── CartItem.java │ │ ├── LineItem.java │ │ ├── Cart.java │ │ ├── Item.java │ │ └── Account.java │ │ ├── web │ │ └── actions │ │ │ ├── AbstractActionBean.java │ │ │ └── CartActionBean.java │ │ └── service │ │ ├── AccountService.java │ │ ├── CatalogService.java │ │ └── OrderService.java └── site │ ├── resources │ ├── images │ │ ├── en.png │ │ ├── es.png │ │ ├── fr.png │ │ ├── ja.png │ │ ├── ko.png │ │ └── zh.png │ └── css │ │ └── site.css │ ├── site_ko.xml │ ├── site_ja.xml │ ├── site.xml │ └── site_es.xml ├── .gitattributes ├── .mvn ├── maven.config ├── extensions.xml ├── wrapper │ └── maven-wrapper.properties └── settings.xml ├── Dockerfile ├── renovate.json ├── .gitignore ├── LICENSE_HEADER ├── format.xml ├── docker-compose.yaml ├── deployment-service.yaml ├── .github └── workflows │ ├── sonatype.yaml │ ├── sonar.yaml │ ├── ci.yaml │ ├── coveralls.yaml │ └── support.yaml ├── NOTICE └── README.md /src/test/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Daether.checksums.algorithms=SHA-512,SHA-256,SHA-1,MD5 2 | -------------------------------------------------------------------------------- /src/main/webapp/images/cart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/cart.gif -------------------------------------------------------------------------------- /src/main/webapp/images/cat1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/cat1.gif -------------------------------------------------------------------------------- /src/main/webapp/images/cat2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/cat2.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dog1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dog1.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dog2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dog2.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dog3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dog3.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dog4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dog4.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dog5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dog5.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dog6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dog6.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dogs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dogs.gif -------------------------------------------------------------------------------- /src/main/webapp/images/fish.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/fish.gif -------------------------------------------------------------------------------- /src/main/webapp/images/bird1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/bird1.gif -------------------------------------------------------------------------------- /src/main/webapp/images/bird2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/bird2.gif -------------------------------------------------------------------------------- /src/main/webapp/images/fish1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/fish1.gif -------------------------------------------------------------------------------- /src/main/webapp/images/fish2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/fish2.gif -------------------------------------------------------------------------------- /src/main/webapp/images/fish3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/fish3.gif -------------------------------------------------------------------------------- /src/main/webapp/images/fish4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/fish4.gif -------------------------------------------------------------------------------- /src/main/webapp/images/snake1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/snake1.gif -------------------------------------------------------------------------------- /src/main/webapp/images/splash.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/splash.gif -------------------------------------------------------------------------------- /src/site/resources/images/en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/site/resources/images/en.png -------------------------------------------------------------------------------- /src/site/resources/images/es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/site/resources/images/es.png -------------------------------------------------------------------------------- /src/site/resources/images/fr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/site/resources/images/fr.png -------------------------------------------------------------------------------- /src/site/resources/images/ja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/site/resources/images/ja.png -------------------------------------------------------------------------------- /src/site/resources/images/ko.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/site/resources/images/ko.png -------------------------------------------------------------------------------- /src/site/resources/images/zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/site/resources/images/zh.png -------------------------------------------------------------------------------- /src/main/webapp/images/cats_icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/cats_icon.gif -------------------------------------------------------------------------------- /src/main/webapp/images/dogs_icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/dogs_icon.gif -------------------------------------------------------------------------------- /src/main/webapp/images/fish_icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/fish_icon.gif -------------------------------------------------------------------------------- /src/main/webapp/images/lizard1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/lizard1.gif -------------------------------------------------------------------------------- /src/main/webapp/images/poweredby.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/poweredby.gif -------------------------------------------------------------------------------- /src/main/webapp/images/separator.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/separator.gif -------------------------------------------------------------------------------- /src/main/webapp/images/sm_birds.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/sm_birds.gif -------------------------------------------------------------------------------- /src/main/webapp/images/sm_cats.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/sm_cats.gif -------------------------------------------------------------------------------- /src/main/webapp/images/sm_dogs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/sm_dogs.gif -------------------------------------------------------------------------------- /src/main/webapp/images/sm_fish.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/sm_fish.gif -------------------------------------------------------------------------------- /src/main/webapp/images/banner_cats.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/banner_cats.gif -------------------------------------------------------------------------------- /src/main/webapp/images/banner_dogs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/banner_dogs.gif -------------------------------------------------------------------------------- /src/main/webapp/images/banner_fish.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/banner_fish.gif -------------------------------------------------------------------------------- /src/main/webapp/images/birds_icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/birds_icon.gif -------------------------------------------------------------------------------- /src/main/webapp/images/logo-topbar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/logo-topbar.gif -------------------------------------------------------------------------------- /src/main/webapp/images/sm_reptiles.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/sm_reptiles.gif -------------------------------------------------------------------------------- /src/main/webapp/images/banner_birds.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/banner_birds.gif -------------------------------------------------------------------------------- /src/main/webapp/images/reptiles_icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/reptiles_icon.gif -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17.0.2 2 | COPY . /usr/src/myapp 3 | WORKDIR /usr/src/myapp 4 | RUN ./mvnw clean package 5 | CMD ./mvnw cargo:run -P tomcat90 -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /src/main/webapp/images/banner_reptiles.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaiswaladi246/jpetstore-6/HEAD/src/main/webapp/images/banner_reptiles.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.settings 3 | /.classpath 4 | /.project 5 | /.idea 6 | *.iml 7 | /build 8 | .mvn/wrapper/maven-wrapper.jar 9 | *.releaseBackup 10 | *.properties 11 | .env -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Copyright ${license.git.copyrightYears} the original author or authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /src/main/resources/StripesResources.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2022 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | -------------------------------------------------------------------------------- /format.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/common/Error.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 21 | 22 | <%@ include file="../common/IncludeBottom.jsp"%> -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2023 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | version: "3.9" 18 | 19 | services: 20 | jpetstore: 21 | container_name: jpetstore 22 | build: 23 | context: . 24 | ports: 25 | - 8080:8080 26 | restart: always 27 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | fr.jcgay.maven 22 | maven-profiler 23 | 3.2 24 | 25 | 26 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/SequenceMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import org.mybatis.jpetstore.domain.Sequence; 19 | 20 | /** 21 | * The Interface SequenceMapper. 22 | * 23 | * @author Eduardo Macarron 24 | */ 25 | public interface SequenceMapper { 26 | 27 | Sequence getSequence(Sequence sequence); 28 | 29 | void updateSequence(Sequence sequence); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/CategoryMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.jpetstore.domain.Category; 21 | 22 | /** 23 | * The Interface CategoryMapper. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public interface CategoryMapper { 28 | 29 | List getCategoryList(); 30 | 31 | Category getCategory(String categoryId); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/LineItemMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.jpetstore.domain.LineItem; 21 | 22 | /** 23 | * The Interface LineItemMapper. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public interface LineItemMapper { 28 | 29 | List getLineItemsByOrderId(int orderId); 30 | 31 | void insertLineItem(LineItem lineItem); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /deployment-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment # Kubernetes resource kind we are creating 3 | metadata: 4 | name: jpetstore-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: jpetstore 9 | replicas: 2 # Number of replicas that will be created for this deployment 10 | template: 11 | metadata: 12 | labels: 13 | app: jpetstore 14 | spec: 15 | containers: 16 | - name: jpetstore 17 | image: adijaiswal/cicddevops:6 # Image that will be used to containers in the cluster 18 | imagePullPolicy: IfNotPresent 19 | ports: 20 | - containerPort: 8080 # The port that the container is running on in the cluster 21 | 22 | 23 | --- 24 | 25 | apiVersion: v1 # Kubernetes API version 26 | kind: Service # Kubernetes resource kind we are creating 27 | metadata: # Metadata of the resource kind we are creating 28 | name: jpetstore-ssvc 29 | spec: 30 | selector: 31 | app: jpetstore 32 | ports: 33 | - protocol: "TCP" 34 | port: 8080 # The port that the service is running on in the cluster 35 | targetPort: 8080 # The port exposed by the service 36 | type: LoadBalancer # type of the service. 37 | -------------------------------------------------------------------------------- /src/site/site_ko.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/ProductMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.jpetstore.domain.Product; 21 | 22 | /** 23 | * The Interface ProductMapper. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public interface ProductMapper { 28 | 29 | List getProductListByCategory(String categoryId); 30 | 31 | Product getProduct(String productId); 32 | 33 | List searchProductList(String keywords); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import java.util.List; 19 | 20 | import org.mybatis.jpetstore.domain.Order; 21 | 22 | /** 23 | * The Interface OrderMapper. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public interface OrderMapper { 28 | 29 | List getOrdersByUsername(String username); 30 | 31 | Order getOrder(int orderId); 32 | 33 | void insertOrder(Order order); 34 | 35 | void insertOrderStatus(Order order); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/site/site_ja.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/site/site_es.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/common/IncludeBottom.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | 19 | 20 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/ItemMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import org.mybatis.jpetstore.domain.Item; 22 | 23 | /** 24 | * The Interface ItemMapper. 25 | * 26 | * @author Eduardo Macarron 27 | */ 28 | public interface ItemMapper { 29 | 30 | void updateInventoryQuantity(Map param); 31 | 32 | int getInventoryQuantity(String itemId); 33 | 34 | List getItemListByProduct(String productId); 35 | 36 | Item getItem(String itemId); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/cart/IncludeMyList.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | 19 |

Pet Favorites
20 | Shop for more of your favorite pets here.

21 |
    22 | 23 |
  • 26 | 27 | ${product.name} 28 | (${product.productId})
  • 29 |
    30 |
31 | 32 |
33 | -------------------------------------------------------------------------------- /src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 18 | 20 | 21 | 22 | 23 | 24 | JPetStore Demo 25 | 26 | 27 | 28 | 29 |
30 |

Welcome to JPetStore 6

31 | 32 |

Enter the Store

33 | 34 |

Copyright www.mybatis.org

35 | 36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/SequenceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 31 | 32 | 33 | UPDATE SEQUENCE 34 | SET NEXTID = #{nextId} 35 | WHERE NAME = #{name} 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/mapper/AccountMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import org.mybatis.jpetstore.domain.Account; 19 | 20 | /** 21 | * The Interface AccountMapper. 22 | * 23 | * @author Eduardo Macarron 24 | */ 25 | public interface AccountMapper { 26 | 27 | Account getAccountByUsername(String username); 28 | 29 | Account getAccountByUsernameAndPassword(String username, String password); 30 | 31 | void insertAccount(Account account); 32 | 33 | void insertProfile(Account account); 34 | 35 | void insertSignon(Account account); 36 | 37 | void updateAccount(Account account); 38 | 39 | void updateProfile(Account account); 40 | 41 | void updateSignon(Account account); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/account/SignonForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |
23 | 24 |

Please enter your username and password.

25 |

Username:
26 | Password:

27 | 28 | 29 |
Need a user name and password? Register Now!
32 | 33 | <%@ include file="../common/IncludeBottom.jsp"%> 34 | 35 | -------------------------------------------------------------------------------- /.mvn/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | ossrh 24 | ${env.CI_DEPLOY_USERNAME} 25 | ${env.CI_DEPLOY_PASSWORD} 26 | 27 | 28 | gh-pages 29 | 30 | 31 | github 32 | ${env.CI_DEPLOY_USERNAME} 33 | ${env.GITHUB_TOKEN} 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /.github/workflows/sonatype.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2021 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | name: Sonatype 18 | 19 | on: 20 | push: 21 | branches: 22 | - master 23 | 24 | jobs: 25 | build: 26 | if: github.repository_owner == 'mybatis' && ! contains(toJSON(github.event.head_commit.message), '[maven-release-plugin]') 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v3 30 | - name: Set up JDK 31 | uses: actions/setup-java@v3 32 | with: 33 | java-version: 17 34 | distribution: zulu 35 | - name: Deploy to Sonatype 36 | run: ./mvnw deploy -DskipTests -B --settings ./.mvn/settings.xml -Dlicense.skip=true 37 | env: 38 | CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }} 39 | CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }} 40 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/CategoryMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 34 | 35 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * when new flags are needed, take them from 18 | * 19 | * https://www.printableworldflags.com/flag-icon 20 | * 21 | * that are free for any kind of usage 22 | */ 23 | 24 | ul.i18n {list-style-type:none;} 25 | li.en {background: url('../images/en.png') left no-repeat;padding-left: 32px; margin: 10px} 26 | li.es {background: url('../images/es.png') left no-repeat;padding-left: 32px; margin: 10px} 27 | li.ja {background: url('../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px} 28 | li.fr {background: url('../images/fr.png') left no-repeat;padding-left: 32px; margin: 10px} 29 | li.zh {background: url('../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px} 30 | li.ko {background: url('../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px} 31 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/LineItemMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 36 | 37 | 38 | INSERT INTO LINEITEM (ORDERID, LINENUM, ITEMID, QUANTITY, UNITPRICE) 39 | VALUES (#{orderId}, #{lineNumber}, #{itemId}, #{quantity}, #{unitPrice}) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/account/NewAccountForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |
23 | 24 |

User Information

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
User ID:
New password:
Repeat password:
40 | 41 | <%@ include file="IncludeAccountFields.jsp"%> 42 | 43 | 44 | 45 |
46 | 47 | <%@ include file="../common/IncludeBottom.jsp"%> -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/order/ListOrders.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |

My Orders

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 37 | 39 | 41 | 42 | 43 |
Order IDDateTotal Price
34 | 35 | ${order.orderId} 36 | $
44 | 45 | <%@ include file="../common/IncludeBottom.jsp"%> 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/Sequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * The Class Sequence. 22 | * 23 | * @author Eduardo Macarron 24 | */ 25 | public class Sequence implements Serializable { 26 | 27 | private static final long serialVersionUID = 8278780133180137281L; 28 | 29 | private String name; 30 | private int nextId; 31 | 32 | public Sequence() { 33 | } 34 | 35 | public Sequence(String name, int nextId) { 36 | this.name = name; 37 | this.nextId = nextId; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | 48 | public int getNextId() { 49 | return nextId; 50 | } 51 | 52 | public void setNextId(int nextId) { 53 | this.nextId = nextId; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/catalog/Category.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 23 | 24 |
25 | 26 |

${actionBean.category.name}

27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 41 | 42 | 43 | 44 |
Product IDName
38 | 39 | ${product.productId} 40 | ${product.name}
45 | 46 |
47 | 48 | <%@ include file="../common/IncludeBottom.jsp"%> 49 | 50 | 51 | -------------------------------------------------------------------------------- /.github/workflows/sonar.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2021 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | name: SonarCloud 18 | 19 | on: 20 | push: 21 | branches: 22 | - master 23 | 24 | jobs: 25 | build: 26 | if: github.repository_owner == 'mybatis' 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v3 30 | with: 31 | # Disabling shallow clone is recommended for improving relevancy of reporting 32 | fetch-depth: 0 33 | - name: Set up JDK 34 | uses: actions/setup-java@v3 35 | with: 36 | java-version: 17 37 | distribution: zulu 38 | - name: Analyze with SonarCloud 39 | run: ./mvnw verify jacoco:report sonar:sonar -B -Dsonar.projectKey=mybatis_jpetstore-6 -Dsonar.organization=mybatis -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dlicense.skip=true 40 | env: 41 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 42 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 43 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/account/EditAccountForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |
23 | 24 |

User Information

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
User ID:${actionBean.username}
New password:
Repeat password:
40 | <%@ include file="IncludeAccountFields.jsp"%> 41 | 42 | 43 | 44 |
My Orders
47 | 48 | <%@ include file="../common/IncludeBottom.jsp"%> 49 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2021 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | name: Java CI 18 | 19 | on: [push, pull_request] 20 | 21 | jobs: 22 | test: 23 | runs-on: ${{ matrix.os }} 24 | strategy: 25 | matrix: 26 | os: [ubuntu-latest, macOS-latest, windows-latest] 27 | java: [11, 17, 19, 20-ea] 28 | distribution: ['zulu'] 29 | fail-fast: false 30 | max-parallel: 4 31 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }} 32 | 33 | steps: 34 | - uses: actions/checkout@v3 35 | - name: Set up JDK 36 | uses: actions/setup-java@v3 37 | with: 38 | java-version: ${{ matrix.java }} 39 | distribution: ${{ matrix.distribution }} 40 | - name: Cache local Maven m2 41 | uses: actions/cache@v3 42 | with: 43 | path: ~/.m2 44 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 45 | restore-keys: ${{ runner.os }}-m2 46 | - name: Test with Maven 47 | run: ./mvnw test -B -D"license.skip=true" 48 | -------------------------------------------------------------------------------- /.github/workflows/coveralls.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2021 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | name: Coveralls 18 | 19 | on: [push, pull_request] 20 | 21 | jobs: 22 | build: 23 | if: github.repository_owner == 'mybatis' 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v3 27 | - name: Set up JDK 28 | uses: actions/setup-java@v3 29 | with: 30 | java-version: 11 31 | distribution: zulu 32 | - name: Report Coverage to Coveralls for Pull Requests 33 | if: github.event_name == 'pull_request' 34 | run: ./mvnw test jacoco:report coveralls:report -q -Dlicense.skip=true -DrepoToken=$GITHUB_TOKEN -DserviceName=github -DpullRequest=$PR_NUMBER 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | PR_NUMBER: ${{ github.event.number }} 38 | - name: Report Coverage to Coveralls for General Push 39 | if: github.event_name == 'push' 40 | run: ./mvnw test jacoco:report coveralls:report -q -Dlicense.skip=true -DrepoToken=$GITHUB_TOKEN -DserviceName=github 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/web/actions/AbstractActionBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.web.actions; 17 | 18 | import java.io.Serializable; 19 | 20 | import net.sourceforge.stripes.action.ActionBean; 21 | import net.sourceforge.stripes.action.ActionBeanContext; 22 | import net.sourceforge.stripes.action.SimpleMessage; 23 | 24 | /** 25 | * The Class AbstractActionBean. 26 | * 27 | * @author Eduardo Macarron 28 | */ 29 | public abstract class AbstractActionBean implements ActionBean, Serializable { 30 | 31 | private static final long serialVersionUID = -1767714708233127983L; 32 | 33 | protected static final String ERROR = "/WEB-INF/jsp/common/Error.jsp"; 34 | 35 | protected transient ActionBeanContext context; 36 | 37 | protected void setMessage(String value) { 38 | context.getMessages().add(new SimpleMessage(value)); 39 | } 40 | 41 | @Override 42 | public ActionBeanContext getContext() { 43 | return context; 44 | } 45 | 46 | @Override 47 | public void setContext(ActionBeanContext context) { 48 | this.context = context; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/Category.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * The Class Category. 22 | * 23 | * @author Eduardo Macarron 24 | */ 25 | public class Category implements Serializable { 26 | 27 | private static final long serialVersionUID = 3992469837058393712L; 28 | 29 | private String categoryId; 30 | private String name; 31 | private String description; 32 | 33 | public String getCategoryId() { 34 | return categoryId; 35 | } 36 | 37 | public void setCategoryId(String categoryId) { 38 | this.categoryId = categoryId.trim(); 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getDescription() { 50 | return description; 51 | } 52 | 53 | public void setDescription(String description) { 54 | this.description = description; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return getCategoryId(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/ProductMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 35 | 36 | 45 | 46 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /.github/workflows/support.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2020 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | name: Container Support 18 | 19 | on: [push, pull_request] 20 | 21 | jobs: 22 | test: 23 | runs-on: ${{ matrix.os }} 24 | strategy: 25 | matrix: 26 | os: [ubuntu-latest, macOS-latest, windows-latest] 27 | java: [11] 28 | distribution: ['zulu'] 29 | token: ["tomcat85", "tomcat9", "tomee71", "tomee80", "wildfly13", "wildfly26", "liberty-ee7", "liberty-ee8", "jetty", "glassfish4", "glassfish5", "resin"] 30 | fail-fast: false 31 | max-parallel: 4 32 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}, ${{ matrix.token }} 33 | 34 | steps: 35 | - uses: actions/checkout@v3 36 | - name: Set up JDK 37 | uses: actions/setup-java@v3 38 | with: 39 | java-version: ${{ matrix.java }} 40 | distribution: ${{ matrix.distribution }} 41 | - name: Cache local Maven m2 42 | uses: actions/cache@v3 43 | with: 44 | path: ~/.m2 45 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 46 | restore-keys: ${{ runner.os }}-m2 47 | - name: Test with ${{ matrix.token }} 48 | run: ./mvnw test -P ${{ matrix.token }} 49 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/catalog/SearchProducts.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
 Product IDName
38 | 39 | ${product.description} 40 | 44 | 45 | ${product.productId} 46 | ${product.name}
55 | 56 |
57 | 58 | <%@ include file="../common/IncludeBottom.jsp"%> 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * The Class Product. 22 | * 23 | * @author Eduardo Macarron 24 | */ 25 | public class Product implements Serializable { 26 | 27 | private static final long serialVersionUID = -7492639752670189553L; 28 | 29 | private String productId; 30 | private String categoryId; 31 | private String name; 32 | private String description; 33 | 34 | public String getProductId() { 35 | return productId; 36 | } 37 | 38 | public void setProductId(String productId) { 39 | this.productId = productId.trim(); 40 | } 41 | 42 | public String getCategoryId() { 43 | return categoryId; 44 | } 45 | 46 | public void setCategoryId(String categoryId) { 47 | this.categoryId = categoryId; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | public String getDescription() { 59 | return description; 60 | } 61 | 62 | public void setDescription(String description) { 63 | this.description = description; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return getName(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/order/ShippingForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
Shipping Address
First name:
Last name:
Address 1:
Address 2:
City:
State:
Zip:
Country:
63 | 64 | 65 | 66 |
67 | 68 | <%@ include file="../common/IncludeBottom.jsp"%> -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | import java.math.BigDecimal; 20 | import java.util.Optional; 21 | 22 | /** 23 | * The Class CartItem. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public class CartItem implements Serializable { 28 | 29 | private static final long serialVersionUID = 6620528781626504362L; 30 | 31 | private Item item; 32 | private int quantity; 33 | private boolean inStock; 34 | private BigDecimal total; 35 | 36 | public boolean isInStock() { 37 | return inStock; 38 | } 39 | 40 | public void setInStock(boolean inStock) { 41 | this.inStock = inStock; 42 | } 43 | 44 | public BigDecimal getTotal() { 45 | return total; 46 | } 47 | 48 | public Item getItem() { 49 | return item; 50 | } 51 | 52 | public void setItem(Item item) { 53 | this.item = item; 54 | calculateTotal(); 55 | } 56 | 57 | public int getQuantity() { 58 | return quantity; 59 | } 60 | 61 | public void setQuantity(int quantity) { 62 | this.quantity = quantity; 63 | calculateTotal(); 64 | } 65 | 66 | public void incrementQuantity() { 67 | quantity++; 68 | calculateTotal(); 69 | } 70 | 71 | private void calculateTotal() { 72 | total = Optional.ofNullable(item).map(Item::getListPrice).map(v -> v.multiply(new BigDecimal(quantity))) 73 | .orElse(null); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/web/actions/OrderActionBeanTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.web.actions; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | class OrderActionBeanTest { 23 | 24 | // Test written by Diffblue Cover. 25 | @Test 26 | void getOrderListOutputNull() { 27 | 28 | // Arrange 29 | final OrderActionBean orderActionBean = new OrderActionBean(); 30 | 31 | // Act and Assert result 32 | assertThat(orderActionBean.getOrderList()).isNull(); 33 | 34 | } 35 | 36 | // Test written by Diffblue Cover. 37 | @Test 38 | void isShippingAddressRequiredOutputFalse() { 39 | 40 | // Arrange 41 | final OrderActionBean orderActionBean = new OrderActionBean(); 42 | 43 | // Act and Assert result 44 | assertThat(orderActionBean.isShippingAddressRequired()).isFalse(); 45 | 46 | } 47 | 48 | // Test written by Diffblue Cover. 49 | @Test 50 | void constructorOutputNotNull() { 51 | 52 | // Act, creating object to test constructor 53 | final OrderActionBean actual = new OrderActionBean(); 54 | 55 | // Assert result 56 | assertThat(actual).isNotNull().isNotNull(); 57 | assertThat(actual.getContext()).isNull(); 58 | 59 | } 60 | 61 | // Test written by Diffblue Cover. 62 | @Test 63 | void isConfirmedOutputFalse() { 64 | 65 | // Arrange 66 | final OrderActionBean orderActionBean = new OrderActionBean(); 67 | 68 | // Act and Assert result 69 | assertThat(orderActionBean.isConfirmed()).isFalse(); 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/mapper/SequenceMapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.extension.ExtendWith; 22 | import org.mybatis.jpetstore.domain.Sequence; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.jdbc.core.JdbcTemplate; 25 | import org.springframework.test.context.ContextConfiguration; 26 | import org.springframework.test.context.junit.jupiter.SpringExtension; 27 | import org.springframework.transaction.annotation.Transactional; 28 | 29 | @ExtendWith(SpringExtension.class) 30 | @ContextConfiguration(classes = MapperTestContext.class) 31 | @Transactional 32 | class SequenceMapperTest { 33 | 34 | @Autowired 35 | private SequenceMapper mapper; 36 | 37 | @Autowired 38 | private JdbcTemplate jdbcTemplate; 39 | 40 | @Test 41 | void getSequence() { 42 | // given 43 | 44 | // when 45 | Sequence sequence = mapper.getSequence(new Sequence("ordernum", -1)); 46 | 47 | // then 48 | assertThat(sequence.getName()).isEqualTo("ordernum"); 49 | assertThat(sequence.getNextId()).isEqualTo(1000); 50 | } 51 | 52 | @Test 53 | void updateSequence() { 54 | // given 55 | Sequence sequence = new Sequence("ordernum", 1001); 56 | 57 | // when 58 | mapper.updateSequence(sequence); 59 | 60 | // then 61 | Integer id = jdbcTemplate.queryForObject("SELECT nextid FROM sequence WHERE name = ?", Integer.class, "ordernum"); 62 | assertThat(id).isEqualTo(1001); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/catalog/Item.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 44 | 45 | 46 | 51 | 52 | 53 | 55 | 56 | 57 | 58 | 64 | 65 |
${actionBean.product.description}
${actionBean.item.itemId}
${actionBean.item.attribute1} 38 | ${actionBean.item.attribute2} ${actionBean.item.attribute3} 39 | ${actionBean.item.attribute4} ${actionBean.item.attribute5} 40 | ${actionBean.product.name}
${actionBean.product.name}
47 | Back ordered. 48 | 49 | ${actionBean.item.quantity} in stock. 50 |
61 | 62 | Add to Cart 63 |
66 | 67 |
68 | 69 | <%@ include file="../common/IncludeBottom.jsp"%> 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/mapper/MapperTestContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import javax.sql.DataSource; 19 | 20 | import org.mybatis.spring.SqlSessionFactoryBean; 21 | import org.mybatis.spring.annotation.MapperScan; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.jdbc.core.JdbcTemplate; 25 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 26 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 27 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 28 | import org.springframework.transaction.PlatformTransactionManager; 29 | 30 | @Configuration 31 | @MapperScan("org.mybatis.jpetstore.mapper") 32 | public class MapperTestContext { 33 | 34 | @Bean 35 | DataSource dataSource() { 36 | return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL) 37 | .setScriptEncoding("UTF-8").ignoreFailedDrops(true).addScript("database/jpetstore-hsqldb-schema.sql") 38 | .addScripts("database/jpetstore-hsqldb-dataload.sql").build(); 39 | } 40 | 41 | @Bean 42 | PlatformTransactionManager transactionManager() { 43 | return new DataSourceTransactionManager(dataSource()); 44 | } 45 | 46 | @Bean 47 | SqlSessionFactoryBean sqlSessionFactory() { 48 | SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); 49 | factoryBean.setDataSource(dataSource()); 50 | factoryBean.setTypeAliasesPackage("org.mybatis.jpetstore.domain"); 51 | return factoryBean; 52 | } 53 | 54 | @Bean 55 | JdbcTemplate jdbcTemplate() { 56 | return new JdbcTemplate(dataSource()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.service; 17 | 18 | import java.util.Optional; 19 | 20 | import org.mybatis.jpetstore.domain.Account; 21 | import org.mybatis.jpetstore.mapper.AccountMapper; 22 | import org.springframework.stereotype.Service; 23 | import org.springframework.transaction.annotation.Transactional; 24 | 25 | /** 26 | * The Class AccountService. 27 | * 28 | * @author Eduardo Macarron 29 | */ 30 | @Service 31 | public class AccountService { 32 | 33 | private final AccountMapper accountMapper; 34 | 35 | public AccountService(AccountMapper accountMapper) { 36 | this.accountMapper = accountMapper; 37 | } 38 | 39 | public Account getAccount(String username) { 40 | return accountMapper.getAccountByUsername(username); 41 | } 42 | 43 | public Account getAccount(String username, String password) { 44 | return accountMapper.getAccountByUsernameAndPassword(username, password); 45 | } 46 | 47 | /** 48 | * Insert account. 49 | * 50 | * @param account 51 | * the account 52 | */ 53 | @Transactional 54 | public void insertAccount(Account account) { 55 | accountMapper.insertAccount(account); 56 | accountMapper.insertProfile(account); 57 | accountMapper.insertSignon(account); 58 | } 59 | 60 | /** 61 | * Update account. 62 | * 63 | * @param account 64 | * the account 65 | */ 66 | @Transactional 67 | public void updateAccount(Account account) { 68 | accountMapper.updateAccount(account); 69 | accountMapper.updateProfile(account); 70 | 71 | Optional.ofNullable(account.getPassword()).filter(password -> password.length() > 0) 72 | .ifPresent(password -> accountMapper.updateSignon(account)); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/catalog/Product.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 22 | 23 | 30 | 31 |
32 | 33 |

${actionBean.product.name}

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 51 | 52 | 54 | 56 | 62 | 63 | 64 | 65 | 67 | 68 |
Item IDProduct IDDescriptionList Price 
48 | 49 | ${item.itemId} 50 | ${item.product.productId}${item.attribute1} ${item.attribute2} ${item.attribute3} 53 | ${item.attribute4} ${item.attribute5} ${actionBean.product.name} 59 | 60 | Add to Cart 61 |
66 |
69 | 70 |
71 | 72 | <%@ include file="../common/IncludeBottom.jsp"%> 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/cart/Checkout.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 23 | 24 |
25 | 26 | 27 | 28 | 70 | 71 | 72 |
29 |

Checkout Summary

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 51 | 52 | 55 | 56 | 57 | 59 | 61 | 62 | 63 | 64 | 66 | 67 |
Item IDProduct IDDescriptionIn Stock?QuantityList PriceTotal Cost
48 | 49 | ${cartItem.item.itemId} 50 | ${cartItem.item.product.productId}${cartItem.item.attribute1} ${cartItem.item.attribute2} 53 | ${cartItem.item.attribute3} ${cartItem.item.attribute4} 54 | ${cartItem.item.attribute5} ${cartItem.item.product.name}${cartItem.inStock}${cartItem.quantity}
Sub Total:
68 | 69 |
 
73 | 74 |
75 | 76 | <%@ include file="../common/IncludeBottom.jsp"%> -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 23 | JPetStore 24 | Online Pet Store Sample Application 25 | 26 | javax.servlet.jsp.jstl.fmt.localizationContext 27 | StripesResources 28 | 29 | 30 | org.springframework.web.context.ContextLoaderListener 31 | 32 | 33 | Stripes Filter 34 | StripesFilter 35 | net.sourceforge.stripes.controller.StripesFilter 36 | 37 | ActionResolver.Packages 38 | org.mybatis.jpetstore.web 39 | 40 | 41 | Extension.Packages 42 | net.sourceforge.stripes.integration.spring 43 | 44 | 45 | 46 | StripesFilter 47 | StripesDispatcher 48 | REQUEST 49 | 50 | 51 | StripesDispatcher 52 | net.sourceforge.stripes.controller.DispatcherServlet 53 | 1 54 | 55 | 56 | StripesDispatcher 57 | *.action 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/account/IncludeAccountFields.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 |

Account Information

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
First name:
Last name:
Email:
Phone:
Address 1:
Address 2:
City:
State:
Zip:
Country:
62 | 63 |

Profile Information

64 | 65 | 66 | 67 | 68 | 71 | 72 | 73 | 74 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 |
Language Preference: 69 | 70 |
Favourite Category: 75 | 76 |
Enable MyList
Enable MyBanner
88 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/ItemMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 46 | 47 | 69 | 70 | 75 | 76 | 77 | UPDATE INVENTORY SET 78 | QTY = QTY - #{increment} 79 | WHERE ITEMID = #{itemId} 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/order/NewOrderForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 85 |
Payment Details
Card Type: 30 | 32 |
Card Number: * Use a fake 37 | number!
Expiry Date (MM/YYYY):
Billing Address
First name:
Last name:
Address 1:
Address 2:
City:
State:
Zip:
Country:
82 | Ship to different address...
86 | 87 | 88 | 89 |
90 | 91 | <%@ include file="../common/IncludeBottom.jsp"%> -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | MyBatis JPetStore 2 | Copyright 2010-2013 3 | 4 | This product includes software developed by 5 | The MyBatis Team (http://mybatis.org/). 6 | 7 | iBATIS 8 | This product includes software developed by 9 | The Apache Software Foundation (http://www.apache.org/). 10 | 11 | Copyright 2010 The Apache Software Foundation 12 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); 14 | you may not use this file except in compliance with the License. 15 | You may obtain a copy of the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software 20 | distributed under the License is distributed on an "AS IS" BASIS, 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and 23 | limitations under the License. 24 | 25 | OGNL 26 | //-------------------------------------------------------------------------- 27 | // Copyright (c) 2004, Drew Davidson and Luke Blanshard 28 | // All rights reserved. 29 | // 30 | // Redistribution and use in source and binary forms, with or without 31 | // modification, are permitted provided that the following conditions are 32 | // met: 33 | // 34 | // Redistributions of source code must retain the above copyright notice, 35 | // this list of conditions and the following disclaimer. 36 | // Redistributions in binary form must reproduce the above copyright 37 | // notice, this list of conditions and the following disclaimer in the 38 | // documentation and/or other materials provided with the distribution. 39 | // Neither the name of the Drew Davidson nor the names of its contributors 40 | // may be used to endorse or promote products derived from this software 41 | // without specific prior written permission. 42 | // 43 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 46 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 47 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 50 | // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 51 | // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 52 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 53 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 54 | // DAMAGE. 55 | //-------------------------------------------------------------------------- 56 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/service/CatalogService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.service; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import org.mybatis.jpetstore.domain.Category; 22 | import org.mybatis.jpetstore.domain.Item; 23 | import org.mybatis.jpetstore.domain.Product; 24 | import org.mybatis.jpetstore.mapper.CategoryMapper; 25 | import org.mybatis.jpetstore.mapper.ItemMapper; 26 | import org.mybatis.jpetstore.mapper.ProductMapper; 27 | import org.springframework.stereotype.Service; 28 | 29 | /** 30 | * The Class CatalogService. 31 | * 32 | * @author Eduardo Macarron 33 | */ 34 | @Service 35 | public class CatalogService { 36 | 37 | private final CategoryMapper categoryMapper; 38 | private final ItemMapper itemMapper; 39 | private final ProductMapper productMapper; 40 | 41 | public CatalogService(CategoryMapper categoryMapper, ItemMapper itemMapper, ProductMapper productMapper) { 42 | this.categoryMapper = categoryMapper; 43 | this.itemMapper = itemMapper; 44 | this.productMapper = productMapper; 45 | } 46 | 47 | public List getCategoryList() { 48 | return categoryMapper.getCategoryList(); 49 | } 50 | 51 | public Category getCategory(String categoryId) { 52 | return categoryMapper.getCategory(categoryId); 53 | } 54 | 55 | public Product getProduct(String productId) { 56 | return productMapper.getProduct(productId); 57 | } 58 | 59 | public List getProductListByCategory(String categoryId) { 60 | return productMapper.getProductListByCategory(categoryId); 61 | } 62 | 63 | /** 64 | * Search product list. 65 | * 66 | * @param keywords 67 | * the keywords 68 | * 69 | * @return the list 70 | */ 71 | public List searchProductList(String keywords) { 72 | List products = new ArrayList<>(); 73 | for (String keyword : keywords.split("\\s+")) { 74 | products.addAll(productMapper.searchProductList("%" + keyword.toLowerCase() + "%")); 75 | } 76 | return products; 77 | } 78 | 79 | public List getItemListByProduct(String productId) { 80 | return itemMapper.getItemListByProduct(productId); 81 | } 82 | 83 | public Item getItem(String itemId) { 84 | return itemMapper.getItem(itemId); 85 | } 86 | 87 | public boolean isItemInStock(String itemId) { 88 | return itemMapper.getInventoryQuantity(itemId) > 0; 89 | } 90 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MyBatis JPetStore 2 | ================= 3 | 4 | [![Java CI](https://github.com/mybatis/jpetstore-6/actions/workflows/ci.yaml/badge.svg)](https://github.com/mybatis/jpetstore-6/actions/workflows/ci.yaml) 5 | [![Container Support](https://github.com/mybatis/jpetstore-6/actions/workflows/support.yaml/badge.svg)](https://github.com/mybatis/jpetstore-6/actions/workflows/support.yaml) 6 | [![Coverage Status](https://coveralls.io/repos/github/mybatis/jpetstore-6/badge.svg?branch=master)](https://coveralls.io/github/mybatis/jpetstore-6?branch=master) 7 | [![License](https://img.shields.io/:license-apache-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 8 | 9 | ![mybatis-jpetstore](https://mybatis.org/images/mybatis-logo.png) 10 | 11 | JPetStore 6 is a full web application built on top of MyBatis 3, Spring 5 and Stripes. 12 | 13 | Essentials 14 | ---------- 15 | 16 | * [See the docs](http://www.mybatis.org/jpetstore-6) 17 | 18 | ## Other versions that you may want to know about 19 | 20 | - JPetstore on top of Spring, Spring MVC, MyBatis 3, and Spring Security https://github.com/making/spring-jpetstore 21 | - JPetstore with Vaadin and Spring Boot with Java Config https://github.com/igor-baiborodine/jpetstore-6-vaadin-spring-boot 22 | - JPetstore on MyBatis Spring Boot Starter https://github.com/kazuki43zoo/mybatis-spring-boot-jpetstore 23 | 24 | ## Run on Application Server 25 | Running JPetStore sample under Tomcat (using the [cargo-maven2-plugin](https://codehaus-cargo.github.io/cargo/Maven2+plugin.html)). 26 | 27 | - Clone this repository 28 | 29 | ``` 30 | $ git clone https://github.com/mybatis/jpetstore-6.git 31 | ``` 32 | 33 | - Build war file 34 | 35 | ``` 36 | $ cd jpetstore-6 37 | $ ./mvnw clean package 38 | ``` 39 | 40 | - Startup the Tomcat server and deploy web application 41 | 42 | ``` 43 | $ ./mvnw cargo:run -P tomcat90 44 | ``` 45 | 46 | > Note: 47 | > 48 | > We provide maven profiles per application server as follow: 49 | > 50 | > | Profile | Description | 51 | > | -------------- | ----------- | 52 | > | tomcat90 | Running under the Tomcat 9.0 | 53 | > | tomcat85 | Running under the Tomcat 8.5 | 54 | > | tomee80 | Running under the TomEE 8.0(Java EE 8) | 55 | > | tomee71 | Running under the TomEE 7.1(Java EE 7) | 56 | > | wildfly26 | Running under the WildFly 26(Java EE 8) | 57 | > | wildfly13 | Running under the WildFly 13(Java EE 7) | 58 | > | liberty-ee8 | Running under the WebSphere Liberty(Java EE 8) | 59 | > | liberty-ee7 | Running under the WebSphere Liberty(Java EE 7) | 60 | > | jetty | Running under the Jetty 9 | 61 | > | glassfish5 | Running under the GlassFish 5(Java EE 8) | 62 | > | glassfish4 | Running under the GlassFish 4(Java EE 7) | 63 | > | resin | Running under the Resin 4 | 64 | 65 | - Run application in browser http://localhost:8080/jpetstore/ 66 | - Press Ctrl-C to stop the server. 67 | 68 | ## Run on Docker 69 | ``` 70 | docker build . -t jpetstore 71 | docker run -p 8080:8080 jpetstore 72 | ``` 73 | or with Docker Compose: 74 | ``` 75 | docker compose up -d 76 | ``` 77 | 78 | ## Try integration tests 79 | 80 | Perform integration tests for screen transition. 81 | 82 | ``` 83 | $ ./mvnw clean verify -P tomcat90 84 | ``` 85 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/LineItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | import java.math.BigDecimal; 20 | import java.util.Optional; 21 | 22 | /** 23 | * The Class LineItem. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public class LineItem implements Serializable { 28 | 29 | private static final long serialVersionUID = 6804536240033522156L; 30 | 31 | private int orderId; 32 | private int lineNumber; 33 | private int quantity; 34 | private String itemId; 35 | private BigDecimal unitPrice; 36 | private Item item; 37 | private BigDecimal total; 38 | 39 | public LineItem() { 40 | } 41 | 42 | /** 43 | * Instantiates a new line item. 44 | * 45 | * @param lineNumber 46 | * the line number 47 | * @param cartItem 48 | * the cart item 49 | */ 50 | public LineItem(int lineNumber, CartItem cartItem) { 51 | this.lineNumber = lineNumber; 52 | this.quantity = cartItem.getQuantity(); 53 | this.itemId = cartItem.getItem().getItemId(); 54 | this.unitPrice = cartItem.getItem().getListPrice(); 55 | this.item = cartItem.getItem(); 56 | calculateTotal(); 57 | } 58 | 59 | public int getOrderId() { 60 | return orderId; 61 | } 62 | 63 | public void setOrderId(int orderId) { 64 | this.orderId = orderId; 65 | } 66 | 67 | public int getLineNumber() { 68 | return lineNumber; 69 | } 70 | 71 | public void setLineNumber(int lineNumber) { 72 | this.lineNumber = lineNumber; 73 | } 74 | 75 | public String getItemId() { 76 | return itemId; 77 | } 78 | 79 | public void setItemId(String itemId) { 80 | this.itemId = itemId; 81 | } 82 | 83 | public BigDecimal getUnitPrice() { 84 | return unitPrice; 85 | } 86 | 87 | public void setUnitPrice(BigDecimal unitprice) { 88 | this.unitPrice = unitprice; 89 | } 90 | 91 | public BigDecimal getTotal() { 92 | return total; 93 | } 94 | 95 | public Item getItem() { 96 | return item; 97 | } 98 | 99 | public void setItem(Item item) { 100 | this.item = item; 101 | calculateTotal(); 102 | } 103 | 104 | public int getQuantity() { 105 | return quantity; 106 | } 107 | 108 | public void setQuantity(int quantity) { 109 | this.quantity = quantity; 110 | calculateTotal(); 111 | } 112 | 113 | private void calculateTotal() { 114 | total = Optional.ofNullable(item).map(Item::getListPrice).map(v -> v.multiply(new BigDecimal(quantity))) 115 | .orElse(null); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/service/AccountServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.service; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.mockito.ArgumentMatchers.eq; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.when; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.mockito.InjectMocks; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.jupiter.MockitoExtension; 28 | import org.mybatis.jpetstore.domain.Account; 29 | import org.mybatis.jpetstore.mapper.AccountMapper; 30 | 31 | /** 32 | * @author Eduardo Macarron 33 | */ 34 | @ExtendWith(MockitoExtension.class) 35 | class AccountServiceTest { 36 | 37 | @Mock 38 | private AccountMapper accountMapper; 39 | 40 | @InjectMocks 41 | private AccountService accountService; 42 | 43 | @Test 44 | void shouldCallTheMapperToInsertAnAccount() { 45 | // given 46 | Account account = new Account(); 47 | 48 | // when 49 | accountService.insertAccount(account); 50 | 51 | // then 52 | verify(accountMapper).insertAccount(eq(account)); 53 | verify(accountMapper).insertProfile(eq(account)); 54 | verify(accountMapper).insertSignon(eq(account)); 55 | } 56 | 57 | @Test 58 | void shouldCallTheMapperToUpdateAnAccount() { 59 | // given 60 | Account account = new Account(); 61 | account.setPassword("foo"); 62 | 63 | // when 64 | accountService.updateAccount(account); 65 | 66 | // then 67 | verify(accountMapper).updateAccount(eq(account)); 68 | verify(accountMapper).updateProfile(eq(account)); 69 | verify(accountMapper).updateSignon(eq(account)); 70 | } 71 | 72 | @Test 73 | void shouldCallTheMapperToGetAccountAnUsername() { 74 | // given 75 | String username = "bar"; 76 | Account expectedAccount = new Account(); 77 | when(accountMapper.getAccountByUsername(username)).thenReturn(expectedAccount); 78 | 79 | // when 80 | Account account = accountService.getAccount(username); 81 | 82 | // then 83 | assertThat(account).isSameAs(expectedAccount); 84 | } 85 | 86 | @Test 87 | void shouldCallTheMapperToGetAccountAnUsernameAndPassword() { 88 | // given 89 | String username = "bar"; 90 | String password = "foo"; 91 | 92 | // when 93 | Account expectedAccount = new Account(); 94 | when(accountMapper.getAccountByUsernameAndPassword(username, password)).thenReturn(expectedAccount); 95 | Account account = accountService.getAccount(username, password); 96 | 97 | // then 98 | assertThat(account).isSameAs(expectedAccount); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/mapper/LineItemMapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.extension.ExtendWith; 26 | import org.mybatis.jpetstore.domain.LineItem; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | import org.springframework.jdbc.core.JdbcTemplate; 29 | import org.springframework.test.context.ContextConfiguration; 30 | import org.springframework.test.context.junit.jupiter.SpringExtension; 31 | import org.springframework.transaction.annotation.Transactional; 32 | 33 | @ExtendWith(SpringExtension.class) 34 | @ContextConfiguration(classes = MapperTestContext.class) 35 | @Transactional 36 | class LineItemMapperTest { 37 | 38 | @Autowired 39 | private LineItemMapper mapper; 40 | 41 | @Autowired 42 | private JdbcTemplate jdbcTemplate; 43 | 44 | @Test 45 | void insertLineItem() { 46 | // given 47 | LineItem lineItem = new LineItem(); 48 | lineItem.setOrderId(1); 49 | lineItem.setLineNumber(1); 50 | lineItem.setItemId("EST-1"); 51 | lineItem.setQuantity(4); 52 | lineItem.setUnitPrice(BigDecimal.valueOf(100)); 53 | 54 | // when 55 | mapper.insertLineItem(lineItem); 56 | 57 | // then 58 | Map record = jdbcTemplate.queryForMap("SELECT * FROM lineitem WHERE orderid = ? AND linenum = ?", 1, 59 | 1); 60 | assertThat(record).hasSize(5).containsEntry("ORDERID", lineItem.getOrderId()) 61 | .containsEntry("LINENUM", lineItem.getLineNumber()).containsEntry("ITEMID", lineItem.getItemId()) 62 | .containsEntry("QUANTITY", lineItem.getQuantity()).containsEntry("UNITPRICE", new BigDecimal("100.00")); 63 | 64 | } 65 | 66 | @Test 67 | void getLineItemsByOrderId() { 68 | // given 69 | LineItem lineItem = new LineItem(); 70 | lineItem.setOrderId(1); 71 | lineItem.setLineNumber(1); 72 | lineItem.setItemId("EST-1"); 73 | lineItem.setQuantity(4); 74 | lineItem.setUnitPrice(BigDecimal.valueOf(100)); 75 | mapper.insertLineItem(lineItem); 76 | 77 | // when 78 | List lineItems = mapper.getLineItemsByOrderId(1); 79 | 80 | // then 81 | assertThat(lineItems).hasSize(1); 82 | assertThat(lineItems.get(0).getOrderId()).isEqualTo(lineItem.getOrderId()); 83 | assertThat(lineItems.get(0).getLineNumber()).isEqualTo(lineItem.getOrderId()); 84 | assertThat(lineItems.get(0).getItemId()).isEqualTo(lineItem.getItemId()); 85 | assertThat(lineItems.get(0).getQuantity()).isEqualTo(lineItem.getQuantity()); 86 | assertThat(lineItems.get(0).getUnitPrice()).isEqualTo(new BigDecimal("100.00")); 87 | 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/catalog/Main.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 |
21 |
23 | 24 | Welcome ${sessionScope.accountBean.account.firstName}! 25 | 26 |
27 |
28 | 29 |
30 | 67 | 68 |
69 |
70 | 71 | Birds 73 | Fish 75 | Dogs 77 | Reptiles 79 | Cats 81 | Birds 83 | 84 |
86 |
87 | 88 |
 
89 |
90 | 91 | <%@ include file="../common/IncludeBottom.jsp"%> 92 | 93 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/order/ConfirmOrder.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 24 | 25 |
Please confirm the information below and then 26 | press continue... 27 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 |
Order 31 |
32 | 34 |
Billing Address
First name:
Last name:
Address 1:
Address 2:
City:
State:
Zip:
Country:
Shipping Address
First name:
Last name:
Address 1:
Address 2:
City:
State:
Zip:
Country:
109 | 110 | 113 | 114 | Confirm 115 |
116 | 117 | <%@ include file="../common/IncludeBottom.jsp"%> 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | import java.math.BigDecimal; 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.HashMap; 23 | import java.util.Iterator; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * The Class Cart. 29 | * 30 | * @author Eduardo Macarron 31 | */ 32 | public class Cart implements Serializable { 33 | 34 | private static final long serialVersionUID = 8329559983943337176L; 35 | 36 | private final Map itemMap = Collections.synchronizedMap(new HashMap<>()); 37 | private final List itemList = new ArrayList<>(); 38 | 39 | public Iterator getCartItems() { 40 | return itemList.iterator(); 41 | } 42 | 43 | public List getCartItemList() { 44 | return itemList; 45 | } 46 | 47 | public int getNumberOfItems() { 48 | return itemList.size(); 49 | } 50 | 51 | public Iterator getAllCartItems() { 52 | return itemList.iterator(); 53 | } 54 | 55 | public boolean containsItemId(String itemId) { 56 | return itemMap.containsKey(itemId); 57 | } 58 | 59 | /** 60 | * Adds the item. 61 | * 62 | * @param item 63 | * the item 64 | * @param isInStock 65 | * the is in stock 66 | */ 67 | public void addItem(Item item, boolean isInStock) { 68 | CartItem cartItem = itemMap.get(item.getItemId()); 69 | if (cartItem == null) { 70 | cartItem = new CartItem(); 71 | cartItem.setItem(item); 72 | cartItem.setQuantity(0); 73 | cartItem.setInStock(isInStock); 74 | itemMap.put(item.getItemId(), cartItem); 75 | itemList.add(cartItem); 76 | } 77 | cartItem.incrementQuantity(); 78 | } 79 | 80 | /** 81 | * Removes the item by id. 82 | * 83 | * @param itemId 84 | * the item id 85 | * 86 | * @return the item 87 | */ 88 | public Item removeItemById(String itemId) { 89 | CartItem cartItem = itemMap.remove(itemId); 90 | if (cartItem == null) { 91 | return null; 92 | } else { 93 | itemList.remove(cartItem); 94 | return cartItem.getItem(); 95 | } 96 | } 97 | 98 | /** 99 | * Increment quantity by item id. 100 | * 101 | * @param itemId 102 | * the item id 103 | */ 104 | public void incrementQuantityByItemId(String itemId) { 105 | CartItem cartItem = itemMap.get(itemId); 106 | cartItem.incrementQuantity(); 107 | } 108 | 109 | public void setQuantityByItemId(String itemId, int quantity) { 110 | CartItem cartItem = itemMap.get(itemId); 111 | cartItem.setQuantity(quantity); 112 | } 113 | 114 | /** 115 | * Gets the sub total. 116 | * 117 | * @return the sub total 118 | */ 119 | public BigDecimal getSubTotal() { 120 | return itemList.stream() 121 | .map(cartItem -> cartItem.getItem().getListPrice().multiply(new BigDecimal(cartItem.getQuantity()))) 122 | .reduce(BigDecimal.ZERO, BigDecimal::add); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/mapper/CategoryMapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import java.util.Comparator; 21 | import java.util.List; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.mybatis.jpetstore.domain.Category; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.test.context.ContextConfiguration; 28 | import org.springframework.test.context.junit.jupiter.SpringExtension; 29 | import org.springframework.transaction.annotation.Transactional; 30 | 31 | @ExtendWith(SpringExtension.class) 32 | @ContextConfiguration(classes = MapperTestContext.class) 33 | @Transactional 34 | class CategoryMapperTest { 35 | 36 | @Autowired 37 | private CategoryMapper mapper; 38 | 39 | @Test 40 | void getCategoryList() { 41 | // given 42 | 43 | // when 44 | List categories = mapper.getCategoryList(); 45 | 46 | // then 47 | categories.sort(Comparator.comparing(Category::getCategoryId)); 48 | assertThat(categories).hasSize(5); 49 | assertThat(categories.get(0).getCategoryId()).isEqualTo("BIRDS"); 50 | assertThat(categories.get(0).getName()).isEqualTo("Birds"); 51 | assertThat(categories.get(0).getDescription()) 52 | .isEqualTo(" Birds"); 53 | assertThat(categories.get(1).getCategoryId()).isEqualTo("CATS"); 54 | assertThat(categories.get(1).getName()).isEqualTo("Cats"); 55 | assertThat(categories.get(1).getDescription()) 56 | .isEqualTo(" Cats"); 57 | assertThat(categories.get(2).getCategoryId()).isEqualTo("DOGS"); 58 | assertThat(categories.get(2).getName()).isEqualTo("Dogs"); 59 | assertThat(categories.get(2).getDescription()) 60 | .isEqualTo(" Dogs"); 61 | assertThat(categories.get(3).getCategoryId()).isEqualTo("FISH"); 62 | assertThat(categories.get(3).getName()).isEqualTo("Fish"); 63 | assertThat(categories.get(3).getDescription()) 64 | .isEqualTo(" Fish"); 65 | assertThat(categories.get(4).getCategoryId()).isEqualTo("REPTILES"); 66 | assertThat(categories.get(4).getName()).isEqualTo("Reptiles"); 67 | assertThat(categories.get(4).getDescription()) 68 | .isEqualTo(" Reptiles"); 69 | } 70 | 71 | @Test 72 | void getCategory() { 73 | // given 74 | String categoryId = "BIRDS"; 75 | 76 | // when 77 | Category category = mapper.getCategory(categoryId); 78 | 79 | // then 80 | assertThat(category.getCategoryId()).isEqualTo("BIRDS"); 81 | assertThat(category.getName()).isEqualTo("Birds"); 82 | assertThat(category.getDescription()) 83 | .isEqualTo(" Birds"); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/domain/OrderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.Date; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | class OrderTest { 26 | 27 | @Test 28 | void initOrder() { 29 | // given 30 | Account account = new Account(); 31 | account.setUsername("mybatis"); 32 | account.setEmail("mybatis@example.com"); 33 | account.setFirstName("My"); 34 | account.setLastName("Batis"); 35 | account.setStatus("NG"); 36 | account.setAddress1("Address 1"); 37 | account.setAddress2("Address 2"); 38 | account.setCity("City"); 39 | account.setState("ST"); 40 | account.setZip("99001"); 41 | account.setCountry("JPN"); 42 | account.setPhone("09012345678"); 43 | 44 | Cart cart = new Cart(); 45 | Item item = new Item(); 46 | item.setItemId("I01"); 47 | item.setListPrice(new BigDecimal("2.05")); 48 | cart.addItem(item, true); 49 | cart.addItem(item, true); 50 | 51 | Order order = new Order(); 52 | 53 | // when 54 | order.initOrder(account, cart); 55 | 56 | // then 57 | assertThat(order.getUsername()).isSameAs(account.getUsername()); 58 | assertThat(order.getOrderDate()).isBeforeOrEqualsTo(new Date()); 59 | assertThat(order.getShipAddress1()).isEqualTo(account.getAddress1()); 60 | assertThat(order.getShipAddress2()).isEqualTo(account.getAddress2()); 61 | assertThat(order.getShipCity()).isEqualTo(account.getCity()); 62 | assertThat(order.getShipState()).isEqualTo(account.getState()); 63 | assertThat(order.getShipCountry()).isEqualTo(account.getCountry()); 64 | assertThat(order.getShipZip()).isEqualTo(account.getZip()); 65 | assertThat(order.getBillAddress1()).isEqualTo(account.getAddress1()); 66 | assertThat(order.getBillAddress2()).isEqualTo(account.getAddress2()); 67 | assertThat(order.getBillCity()).isEqualTo(account.getCity()); 68 | assertThat(order.getBillState()).isEqualTo(account.getState()); 69 | assertThat(order.getBillCountry()).isEqualTo(account.getCountry()); 70 | assertThat(order.getBillZip()).isEqualTo(account.getZip()); 71 | assertThat(order.getTotalPrice()).isEqualTo(new BigDecimal("4.10")); 72 | assertThat(order.getCreditCard()).isEqualTo("999 9999 9999 9999"); 73 | assertThat(order.getCardType()).isEqualTo("Visa"); 74 | assertThat(order.getExpiryDate()).isEqualTo("12/03"); 75 | assertThat(order.getCourier()).isEqualTo("UPS"); 76 | assertThat(order.getLocale()).isEqualTo("CA"); 77 | assertThat(order.getStatus()).isEqualTo("P"); 78 | assertThat(order.getLineItems()).hasSize(1); 79 | assertThat(order.getLineItems().get(0).getItem()).isSameAs(item); 80 | assertThat(order.getLineItems().get(0).getLineNumber()).isEqualTo(1); 81 | assertThat(order.getLineItems().get(0).getItemId()).isEqualTo("I01"); 82 | assertThat(order.getLineItems().get(0).getUnitPrice()).isEqualTo(new BigDecimal("2.05")); 83 | assertThat(order.getLineItems().get(0).getQuantity()).isEqualTo(2); 84 | assertThat(order.getLineItems().get(0).getTotal()).isEqualTo(new BigDecimal("4.10")); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/Item.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | import java.math.BigDecimal; 20 | 21 | /** 22 | * The Class Item. 23 | * 24 | * @author Eduardo Macarron 25 | */ 26 | public class Item implements Serializable { 27 | 28 | private static final long serialVersionUID = -2159121673445254631L; 29 | 30 | private String itemId; 31 | private String productId; 32 | private BigDecimal listPrice; 33 | private BigDecimal unitCost; 34 | private int supplierId; 35 | private String status; 36 | private String attribute1; 37 | private String attribute2; 38 | private String attribute3; 39 | private String attribute4; 40 | private String attribute5; 41 | private Product product; 42 | private int quantity; 43 | 44 | public String getItemId() { 45 | return itemId; 46 | } 47 | 48 | public void setItemId(String itemId) { 49 | this.itemId = itemId.trim(); 50 | } 51 | 52 | public int getQuantity() { 53 | return quantity; 54 | } 55 | 56 | public void setQuantity(int quantity) { 57 | this.quantity = quantity; 58 | } 59 | 60 | public Product getProduct() { 61 | return product; 62 | } 63 | 64 | public void setProduct(Product product) { 65 | this.product = product; 66 | } 67 | 68 | public int getSupplierId() { 69 | return supplierId; 70 | } 71 | 72 | public void setSupplierId(int supplierId) { 73 | this.supplierId = supplierId; 74 | } 75 | 76 | public BigDecimal getListPrice() { 77 | return listPrice; 78 | } 79 | 80 | public void setListPrice(BigDecimal listPrice) { 81 | this.listPrice = listPrice; 82 | } 83 | 84 | public BigDecimal getUnitCost() { 85 | return unitCost; 86 | } 87 | 88 | public void setUnitCost(BigDecimal unitCost) { 89 | this.unitCost = unitCost; 90 | } 91 | 92 | public String getStatus() { 93 | return status; 94 | } 95 | 96 | public void setStatus(String status) { 97 | this.status = status; 98 | } 99 | 100 | public String getAttribute1() { 101 | return attribute1; 102 | } 103 | 104 | public void setAttribute1(String attribute1) { 105 | this.attribute1 = attribute1; 106 | } 107 | 108 | public String getAttribute2() { 109 | return attribute2; 110 | } 111 | 112 | public void setAttribute2(String attribute2) { 113 | this.attribute2 = attribute2; 114 | } 115 | 116 | public String getAttribute3() { 117 | return attribute3; 118 | } 119 | 120 | public void setAttribute3(String attribute3) { 121 | this.attribute3 = attribute3; 122 | } 123 | 124 | public String getAttribute4() { 125 | return attribute4; 126 | } 127 | 128 | public void setAttribute4(String attribute4) { 129 | this.attribute4 = attribute4; 130 | } 131 | 132 | public String getAttribute5() { 133 | return attribute5; 134 | } 135 | 136 | public void setAttribute5(String attribute5) { 137 | this.attribute5 = attribute5; 138 | } 139 | 140 | @Override 141 | public String toString() { 142 | return "(" + getItemId() + "-" + getProduct().getProductId() + ")"; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/cart/Cart.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 23 | 24 |
25 | 26 |
27 | 28 |

Shopping Cart

29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 57 | 58 | 61 | 62 | 64 | 66 | 68 | 74 | 75 | 76 | 77 | 80 | 81 | 82 |
Item IDProduct IDDescriptionIn Stock?QuantityList PriceTotal Cost 
Your cart is empty.
54 | 55 | ${cartItem.item.itemId} 56 | ${cartItem.item.product.productId}${cartItem.item.attribute1} ${cartItem.item.attribute2} 59 | ${cartItem.item.attribute3} ${cartItem.item.attribute4} 60 | ${cartItem.item.attribute5} ${cartItem.item.product.name}${cartItem.inStock}$$ 71 | 72 | Remove 73 |
Sub Total: $  
83 | 84 |
85 | 88 | Proceed to Checkout 89 | 90 |
91 | 92 |
93 | 94 | 95 | 96 | <%@ include file="IncludeMyList.jsp"%> 97 | 98 | 99 | 100 |
101 | 102 |
 
103 |
104 | 105 | <%@ include file="../common/IncludeBottom.jsp"%> -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/web/actions/AccountActionBeanTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.web.actions; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | import org.mybatis.jpetstore.domain.Account; 22 | 23 | class AccountActionBeanTest { 24 | 25 | // Test written by Diffblue Cover. 26 | @Test 27 | void getMyListOutputNull() { 28 | 29 | // Arrange 30 | final AccountActionBean accountActionBean = new AccountActionBean(); 31 | 32 | // Act and Assert result 33 | assertThat(accountActionBean.getMyList()).isNull(); 34 | 35 | } 36 | 37 | // Test written by Diffblue Cover. 38 | @Test 39 | void constructorOutputNotNull() { 40 | 41 | // Act, creating object to test constructor 42 | final AccountActionBean actual = new AccountActionBean(); 43 | 44 | // Assert result 45 | assertThat(actual).isNotNull(); 46 | assertThat(actual.getContext()).isNull(); 47 | 48 | } 49 | 50 | // Test written by Diffblue Cover. 51 | @Test 52 | void getPasswordOutputNull() { 53 | 54 | // Arrange 55 | final AccountActionBean accountActionBean = new AccountActionBean(); 56 | 57 | // Act and Assert result 58 | assertThat(accountActionBean.getPassword()).isNull(); 59 | 60 | } 61 | 62 | // Test written by Diffblue Cover. 63 | @Test 64 | void isAuthenticatedOutputFalse() { 65 | 66 | // Arrange 67 | final AccountActionBean accountActionBean = new AccountActionBean(); 68 | 69 | // Act and Assert result 70 | assertThat(accountActionBean.isAuthenticated()).isFalse(); 71 | 72 | } 73 | 74 | // Test written by Diffblue Cover. 75 | @Test 76 | void getUsernameOutputNull() { 77 | 78 | // Arrange 79 | final AccountActionBean accountActionBean = new AccountActionBean(); 80 | 81 | // Act and Assert result 82 | assertThat(accountActionBean.getUsername()).isNull(); 83 | 84 | } 85 | 86 | // Test written by Diffblue Cover. 87 | @Test 88 | void getAccountOutputNotNull() { 89 | 90 | // Arrange 91 | final AccountActionBean accountActionBean = new AccountActionBean(); 92 | 93 | // Act 94 | final Account actual = accountActionBean.getAccount(); 95 | 96 | // Assert result 97 | assertThat(actual).isNotNull(); 98 | assertThat(actual.getAddress2()).isNull(); 99 | assertThat(actual.getState()).isNull(); 100 | assertThat(actual.getFirstName()).isNull(); 101 | assertThat(actual.getPassword()).isNull(); 102 | assertThat(actual.getLanguagePreference()).isNull(); 103 | assertThat(actual.getFavouriteCategoryId()).isNull(); 104 | assertThat(actual.getCountry()).isNull(); 105 | assertThat(actual.getPhone()).isNull(); 106 | assertThat(actual.getUsername()).isNull(); 107 | assertThat(actual.getLastName()).isNull(); 108 | assertThat(actual.getAddress1()).isNull(); 109 | assertThat(actual.getEmail()).isNull(); 110 | assertThat(actual.getStatus()).isNull(); 111 | assertThat(actual.getBannerName()).isNull(); 112 | assertThat(actual.getZip()).isNull(); 113 | assertThat(actual.getCity()).isNull(); 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/OrderMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 58 | 59 | 92 | 93 | 94 | INSERT INTO ORDERS (ORDERID, USERID, ORDERDATE, SHIPADDR1, SHIPADDR2, SHIPCITY, SHIPSTATE, 95 | SHIPZIP, SHIPCOUNTRY, BILLADDR1, BILLADDR2, BILLCITY, BILLSTATE, BILLZIP, BILLCOUNTRY, 96 | COURIER, TOTALPRICE, BILLTOFIRSTNAME, BILLTOLASTNAME, SHIPTOFIRSTNAME, SHIPTOLASTNAME, 97 | CREDITCARD, EXPRDATE, CARDTYPE, LOCALE) 98 | VALUES(#{orderId}, #{username}, #{orderDate}, #{shipAddress1}, #{shipAddress2,jdbcType=VARCHAR}, #{shipCity}, 99 | #{shipState}, #{shipZip}, #{shipCountry}, #{billAddress1}, #{billAddress2,jdbcType=VARCHAR}, #{billCity}, 100 | #{billState}, #{billZip}, #{billCountry}, #{courier}, #{totalPrice}, #{billToFirstName}, #{billToLastName}, 101 | #{shipToFirstName}, #{shipToLastName}, #{creditCard}, #{expiryDate}, #{cardType}, #{locale}) 102 | 103 | 104 | 105 | INSERT INTO ORDERSTATUS (ORDERID, LINENUM, TIMESTAMP, STATUS) 106 | VALUES (#{orderId,jdbcType=NUMERIC}, #{orderId,jdbcType=NUMERIC}, #{orderDate,jdbcType=TIMESTAMP}, #{status,jdbcType=VARCHAR}) 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/web/actions/CatalogActionBeanTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.web.actions; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | class CatalogActionBeanTest { 23 | 24 | @Test 25 | void getItemListOutputNull() { 26 | 27 | // Arrange 28 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 29 | 30 | // Act and Assert result 31 | assertThat(catalogActionBean.getItemList()).isNull(); 32 | 33 | } 34 | 35 | // Test written by Diffblue Cover. 36 | @Test 37 | void getProductListOutputNull() { 38 | 39 | // Arrange 40 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 41 | 42 | // Act and Assert result 43 | assertThat(catalogActionBean.getProductList()).isNull(); 44 | 45 | } 46 | 47 | // Test written by Diffblue Cover. 48 | @Test 49 | void getCategoryListOutputNull() { 50 | 51 | // Arrange 52 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 53 | 54 | // Act and Assert result 55 | assertThat(catalogActionBean.getCategoryList()).isNull(); 56 | 57 | } 58 | 59 | // Test written by Diffblue Cover. 60 | @Test 61 | void getItemOutputNull() { 62 | 63 | // Arrange 64 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 65 | 66 | // Act and Assert result 67 | assertThat(catalogActionBean.getItem()).isNull(); 68 | 69 | } 70 | 71 | // Test written by Diffblue Cover. 72 | @Test 73 | void getProductOutputNull() { 74 | 75 | // Arrange 76 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 77 | 78 | // Act and Assert result 79 | assertThat(catalogActionBean.getProduct()).isNull(); 80 | 81 | } 82 | 83 | // Test written by Diffblue Cover. 84 | @Test 85 | void getCategoryOutputNull() { 86 | 87 | // Arrange 88 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 89 | 90 | // Act and Assert result 91 | assertThat(catalogActionBean.getCategory()).isNull(); 92 | 93 | } 94 | 95 | // Test written by Diffblue Cover. 96 | @Test 97 | void getItemIdOutputNull() { 98 | 99 | // Arrange 100 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 101 | 102 | // Act and Assert result 103 | assertThat(catalogActionBean.getItemId()).isNull(); 104 | 105 | } 106 | 107 | // Test written by Diffblue Cover. 108 | @Test 109 | void getProductIdOutputNull() { 110 | 111 | // Arrange 112 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 113 | 114 | // Act and Assert result 115 | assertThat(catalogActionBean.getProductId()).isNull(); 116 | 117 | } 118 | 119 | // Test written by Diffblue Cover. 120 | @Test 121 | void getCategoryIdOutputNull() { 122 | 123 | // Arrange 124 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 125 | 126 | // Act and Assert result 127 | assertThat(catalogActionBean.getCategoryId()).isNull(); 128 | 129 | } 130 | 131 | // Test written by Diffblue Cover. 132 | @Test 133 | void getKeywordOutputNull() { 134 | 135 | // Arrange 136 | final CatalogActionBean catalogActionBean = new CatalogActionBean(); 137 | 138 | // Act and Assert result 139 | assertThat(catalogActionBean.getKeyword()).isNull(); 140 | 141 | } 142 | 143 | // Test written by Diffblue Cover. 144 | @Test 145 | void constructorOutputNotNull() { 146 | 147 | // Act, creating object to test constructor 148 | final CatalogActionBean actual = new CatalogActionBean(); 149 | 150 | // Assert result 151 | assertThat(actual).isNotNull(); 152 | assertThat(actual.getContext()).isNull(); 153 | 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.service; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.mybatis.jpetstore.domain.Item; 23 | import org.mybatis.jpetstore.domain.Order; 24 | import org.mybatis.jpetstore.domain.Sequence; 25 | import org.mybatis.jpetstore.mapper.ItemMapper; 26 | import org.mybatis.jpetstore.mapper.LineItemMapper; 27 | import org.mybatis.jpetstore.mapper.OrderMapper; 28 | import org.mybatis.jpetstore.mapper.SequenceMapper; 29 | import org.springframework.stereotype.Service; 30 | import org.springframework.transaction.annotation.Transactional; 31 | 32 | /** 33 | * The Class OrderService. 34 | * 35 | * @author Eduardo Macarron 36 | */ 37 | @Service 38 | public class OrderService { 39 | 40 | private final ItemMapper itemMapper; 41 | private final OrderMapper orderMapper; 42 | private final SequenceMapper sequenceMapper; 43 | private final LineItemMapper lineItemMapper; 44 | 45 | public OrderService(ItemMapper itemMapper, OrderMapper orderMapper, SequenceMapper sequenceMapper, 46 | LineItemMapper lineItemMapper) { 47 | this.itemMapper = itemMapper; 48 | this.orderMapper = orderMapper; 49 | this.sequenceMapper = sequenceMapper; 50 | this.lineItemMapper = lineItemMapper; 51 | } 52 | 53 | /** 54 | * Insert order. 55 | * 56 | * @param order 57 | * the order 58 | */ 59 | @Transactional 60 | public void insertOrder(Order order) { 61 | order.setOrderId(getNextId("ordernum")); 62 | order.getLineItems().forEach(lineItem -> { 63 | String itemId = lineItem.getItemId(); 64 | Integer increment = lineItem.getQuantity(); 65 | Map param = new HashMap<>(2); 66 | param.put("itemId", itemId); 67 | param.put("increment", increment); 68 | itemMapper.updateInventoryQuantity(param); 69 | }); 70 | 71 | orderMapper.insertOrder(order); 72 | orderMapper.insertOrderStatus(order); 73 | order.getLineItems().forEach(lineItem -> { 74 | lineItem.setOrderId(order.getOrderId()); 75 | lineItemMapper.insertLineItem(lineItem); 76 | }); 77 | } 78 | 79 | /** 80 | * Gets the order. 81 | * 82 | * @param orderId 83 | * the order id 84 | * 85 | * @return the order 86 | */ 87 | @Transactional 88 | public Order getOrder(int orderId) { 89 | Order order = orderMapper.getOrder(orderId); 90 | order.setLineItems(lineItemMapper.getLineItemsByOrderId(orderId)); 91 | 92 | order.getLineItems().forEach(lineItem -> { 93 | Item item = itemMapper.getItem(lineItem.getItemId()); 94 | item.setQuantity(itemMapper.getInventoryQuantity(lineItem.getItemId())); 95 | lineItem.setItem(item); 96 | }); 97 | 98 | return order; 99 | } 100 | 101 | /** 102 | * Gets the orders by username. 103 | * 104 | * @param username 105 | * the username 106 | * 107 | * @return the orders by username 108 | */ 109 | public List getOrdersByUsername(String username) { 110 | return orderMapper.getOrdersByUsername(username); 111 | } 112 | 113 | /** 114 | * Gets the next id. 115 | * 116 | * @param name 117 | * the name 118 | * 119 | * @return the next id 120 | */ 121 | public int getNextId(String name) { 122 | Sequence sequence = sequenceMapper.getSequence(new Sequence(name, -1)); 123 | if (sequence == null) { 124 | throw new RuntimeException( 125 | "Error: A null sequence was returned from the database (could not get next " + name + " sequence)."); 126 | } 127 | Sequence parameterObject = new Sequence(name, sequence.getNextId() + 1); 128 | sequenceMapper.updateSequence(parameterObject); 129 | return sequence.getNextId(); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/web/actions/CartActionBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.web.actions; 17 | 18 | import java.util.Iterator; 19 | 20 | import javax.servlet.http.HttpServletRequest; 21 | 22 | import net.sourceforge.stripes.action.ForwardResolution; 23 | import net.sourceforge.stripes.action.Resolution; 24 | import net.sourceforge.stripes.action.SessionScope; 25 | import net.sourceforge.stripes.integration.spring.SpringBean; 26 | 27 | import org.mybatis.jpetstore.domain.Cart; 28 | import org.mybatis.jpetstore.domain.CartItem; 29 | import org.mybatis.jpetstore.domain.Item; 30 | import org.mybatis.jpetstore.service.CatalogService; 31 | 32 | /** 33 | * The Class CartActionBean. 34 | * 35 | * @author Eduardo Macarron 36 | */ 37 | @SessionScope 38 | public class CartActionBean extends AbstractActionBean { 39 | 40 | private static final long serialVersionUID = -4038684592582714235L; 41 | 42 | private static final String VIEW_CART = "/WEB-INF/jsp/cart/Cart.jsp"; 43 | private static final String CHECK_OUT = "/WEB-INF/jsp/cart/Checkout.jsp"; 44 | 45 | @SpringBean 46 | private transient CatalogService catalogService; 47 | 48 | private Cart cart = new Cart(); 49 | private String workingItemId; 50 | 51 | public Cart getCart() { 52 | return cart; 53 | } 54 | 55 | public void setCart(Cart cart) { 56 | this.cart = cart; 57 | } 58 | 59 | public void setWorkingItemId(String workingItemId) { 60 | this.workingItemId = workingItemId; 61 | } 62 | 63 | /** 64 | * Adds the item to cart. 65 | * 66 | * @return the resolution 67 | */ 68 | public Resolution addItemToCart() { 69 | if (cart.containsItemId(workingItemId)) { 70 | cart.incrementQuantityByItemId(workingItemId); 71 | } else { 72 | // isInStock is a "real-time" property that must be updated 73 | // every time an item is added to the cart, even if other 74 | // item details are cached. 75 | boolean isInStock = catalogService.isItemInStock(workingItemId); 76 | Item item = catalogService.getItem(workingItemId); 77 | cart.addItem(item, isInStock); 78 | } 79 | 80 | return new ForwardResolution(VIEW_CART); 81 | } 82 | 83 | /** 84 | * Removes the item from cart. 85 | * 86 | * @return the resolution 87 | */ 88 | public Resolution removeItemFromCart() { 89 | 90 | Item item = cart.removeItemById(workingItemId); 91 | 92 | if (item == null) { 93 | setMessage("Attempted to remove null CartItem from Cart."); 94 | return new ForwardResolution(ERROR); 95 | } else { 96 | return new ForwardResolution(VIEW_CART); 97 | } 98 | } 99 | 100 | /** 101 | * Update cart quantities. 102 | * 103 | * @return the resolution 104 | */ 105 | public Resolution updateCartQuantities() { 106 | HttpServletRequest request = context.getRequest(); 107 | 108 | Iterator cartItems = getCart().getAllCartItems(); 109 | while (cartItems.hasNext()) { 110 | CartItem cartItem = cartItems.next(); 111 | String itemId = cartItem.getItem().getItemId(); 112 | try { 113 | int quantity = Integer.parseInt(request.getParameter(itemId)); 114 | getCart().setQuantityByItemId(itemId, quantity); 115 | if (quantity < 1) { 116 | cartItems.remove(); 117 | } 118 | } catch (Exception e) { 119 | // ignore parse exceptions on purpose 120 | } 121 | } 122 | 123 | return new ForwardResolution(VIEW_CART); 124 | } 125 | 126 | public ForwardResolution viewCart() { 127 | return new ForwardResolution(VIEW_CART); 128 | } 129 | 130 | public ForwardResolution checkOut() { 131 | return new ForwardResolution(CHECK_OUT); 132 | } 133 | 134 | public void clear() { 135 | cart = new Cart(); 136 | workingItemId = null; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/mapper/ProductMapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import java.util.Comparator; 21 | import java.util.List; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.mybatis.jpetstore.domain.Product; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.test.context.ContextConfiguration; 28 | import org.springframework.test.context.junit.jupiter.SpringExtension; 29 | import org.springframework.transaction.annotation.Transactional; 30 | 31 | @ExtendWith(SpringExtension.class) 32 | @ContextConfiguration(classes = MapperTestContext.class) 33 | @Transactional 34 | class ProductMapperTest { 35 | 36 | @Autowired 37 | private ProductMapper mapper; 38 | 39 | @Test 40 | void getProductListByCategory() { 41 | // given 42 | String categoryId = "FISH"; 43 | 44 | // when 45 | List products = mapper.getProductListByCategory(categoryId); 46 | 47 | // then 48 | products.sort(Comparator.comparing(Product::getProductId)); 49 | assertThat(products).hasSize(4); 50 | assertThat(products.get(0).getProductId()).isEqualTo("FI-FW-01"); 51 | assertThat(products.get(0).getName()).isEqualTo("Koi"); 52 | assertThat(products.get(0).getCategoryId()).isEqualTo("FISH"); 53 | assertThat(products.get(0).getDescription()) 54 | .isEqualTo("Fresh Water fish from Japan"); 55 | assertThat(products.get(1).getProductId()).isEqualTo("FI-FW-02"); 56 | assertThat(products.get(1).getName()).isEqualTo("Goldfish"); 57 | assertThat(products.get(1).getCategoryId()).isEqualTo("FISH"); 58 | assertThat(products.get(1).getDescription()) 59 | .isEqualTo("Fresh Water fish from China"); 60 | assertThat(products.get(2).getProductId()).isEqualTo("FI-SW-01"); 61 | assertThat(products.get(2).getName()).isEqualTo("Angelfish"); 62 | assertThat(products.get(2).getCategoryId()).isEqualTo("FISH"); 63 | assertThat(products.get(2).getDescription()) 64 | .isEqualTo("Salt Water fish from Australia"); 65 | assertThat(products.get(3).getProductId()).isEqualTo("FI-SW-02"); 66 | assertThat(products.get(3).getName()).isEqualTo("Tiger Shark"); 67 | assertThat(products.get(3).getCategoryId()).isEqualTo("FISH"); 68 | assertThat(products.get(3).getDescription()) 69 | .isEqualTo("Salt Water fish from Australia"); 70 | } 71 | 72 | @Test 73 | void getProduct() { 74 | // given 75 | String productId = "FI-FW-01"; 76 | 77 | // when 78 | Product product = mapper.getProduct(productId); 79 | 80 | // then 81 | assertThat(product.getProductId()).isEqualTo("FI-FW-01"); 82 | assertThat(product.getName()).isEqualTo("Koi"); 83 | assertThat(product.getCategoryId()).isEqualTo("FISH"); 84 | assertThat(product.getDescription()).isEqualTo("Fresh Water fish from Japan"); 85 | } 86 | 87 | @Test 88 | void searchProductList() { 89 | // given 90 | String keywords = "%o%"; 91 | 92 | // when 93 | List products = mapper.searchProductList(keywords); 94 | 95 | // then 96 | products.sort(Comparator.comparing(Product::getProductId)); 97 | System.out.println(products); 98 | assertThat(products).hasSize(8); 99 | assertThat(products.get(0).getProductId()).isEqualTo("AV-CB-01"); 100 | assertThat(products.get(0).getName()).isEqualTo("Amazon Parrot"); 101 | assertThat(products.get(0).getCategoryId()).isEqualTo("BIRDS"); 102 | assertThat(products.get(0).getDescription()) 103 | .isEqualTo("Great companion for up to 75 years"); 104 | assertThat(products.get(1).getName()).isEqualTo("Koi"); 105 | assertThat(products.get(2).getName()).isEqualTo("Goldfish"); 106 | assertThat(products.get(3).getName()).isEqualTo("Bulldog"); 107 | assertThat(products.get(4).getName()).isEqualTo("Dalmation"); 108 | assertThat(products.get(5).getName()).isEqualTo("Poodle"); 109 | assertThat(products.get(6).getName()).isEqualTo("Golden Retriever"); 110 | assertThat(products.get(7).getName()).isEqualTo("Labrador Retriever"); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/jpetstore/domain/Account.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import java.io.Serializable; 19 | 20 | import net.sourceforge.stripes.validation.Validate; 21 | 22 | /** 23 | * The Class Account. 24 | * 25 | * @author Eduardo Macarron 26 | */ 27 | public class Account implements Serializable { 28 | 29 | private static final long serialVersionUID = 8751282105532159742L; 30 | 31 | private String username; 32 | private String password; 33 | private String email; 34 | private String firstName; 35 | private String lastName; 36 | private String status; 37 | private String address1; 38 | private String address2; 39 | private String city; 40 | private String state; 41 | private String zip; 42 | private String country; 43 | private String phone; 44 | private String favouriteCategoryId; 45 | private String languagePreference; 46 | private boolean listOption; 47 | private boolean bannerOption; 48 | private String bannerName; 49 | 50 | public String getUsername() { 51 | return username; 52 | } 53 | 54 | public void setUsername(String username) { 55 | this.username = username; 56 | } 57 | 58 | public String getPassword() { 59 | return password; 60 | } 61 | 62 | public void setPassword(String password) { 63 | this.password = password; 64 | } 65 | 66 | public String getEmail() { 67 | return email; 68 | } 69 | 70 | public void setEmail(String email) { 71 | this.email = email; 72 | } 73 | 74 | public String getFirstName() { 75 | return firstName; 76 | } 77 | 78 | @Validate(required = true, on = { "newAccount", "editAccount" }) 79 | public void setFirstName(String firstName) { 80 | this.firstName = firstName; 81 | } 82 | 83 | public String getLastName() { 84 | return lastName; 85 | } 86 | 87 | @Validate(required = true, on = { "newAccount", "editAccount" }) 88 | public void setLastName(String lastName) { 89 | this.lastName = lastName; 90 | } 91 | 92 | public String getStatus() { 93 | return status; 94 | } 95 | 96 | public void setStatus(String status) { 97 | this.status = status; 98 | } 99 | 100 | public String getAddress1() { 101 | return address1; 102 | } 103 | 104 | public void setAddress1(String address1) { 105 | this.address1 = address1; 106 | } 107 | 108 | public String getAddress2() { 109 | return address2; 110 | } 111 | 112 | public void setAddress2(String address2) { 113 | this.address2 = address2; 114 | } 115 | 116 | public String getCity() { 117 | return city; 118 | } 119 | 120 | public void setCity(String city) { 121 | this.city = city; 122 | } 123 | 124 | public String getState() { 125 | return state; 126 | } 127 | 128 | public void setState(String state) { 129 | this.state = state; 130 | } 131 | 132 | public String getZip() { 133 | return zip; 134 | } 135 | 136 | public void setZip(String zip) { 137 | this.zip = zip; 138 | } 139 | 140 | public String getCountry() { 141 | return country; 142 | } 143 | 144 | public void setCountry(String country) { 145 | this.country = country; 146 | } 147 | 148 | public String getPhone() { 149 | return phone; 150 | } 151 | 152 | public void setPhone(String phone) { 153 | this.phone = phone; 154 | } 155 | 156 | public String getFavouriteCategoryId() { 157 | return favouriteCategoryId; 158 | } 159 | 160 | public void setFavouriteCategoryId(String favouriteCategoryId) { 161 | this.favouriteCategoryId = favouriteCategoryId; 162 | } 163 | 164 | public String getLanguagePreference() { 165 | return languagePreference; 166 | } 167 | 168 | public void setLanguagePreference(String languagePreference) { 169 | this.languagePreference = languagePreference; 170 | } 171 | 172 | public boolean isListOption() { 173 | return listOption; 174 | } 175 | 176 | public void setListOption(boolean listOption) { 177 | this.listOption = listOption; 178 | } 179 | 180 | public boolean isBannerOption() { 181 | return bannerOption; 182 | } 183 | 184 | public void setBannerOption(boolean bannerOption) { 185 | this.bannerOption = bannerOption; 186 | } 187 | 188 | public String getBannerName() { 189 | return bannerName; 190 | } 191 | 192 | public void setBannerName(String bannerName) { 193 | this.bannerName = bannerName; 194 | } 195 | 196 | } 197 | -------------------------------------------------------------------------------- /src/main/resources/org/mybatis/jpetstore/mapper/AccountMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 51 | 52 | 78 | 79 | 80 | UPDATE ACCOUNT SET 81 | EMAIL = #{email}, 82 | FIRSTNAME = #{firstName}, 83 | LASTNAME = #{lastName}, 84 | STATUS = #{status}, 85 | ADDR1 = #{address1}, 86 | ADDR2 = #{address2,jdbcType=VARCHAR}, 87 | CITY = #{city}, 88 | STATE = #{state}, 89 | ZIP = #{zip}, 90 | COUNTRY = #{country}, 91 | PHONE = #{phone} 92 | WHERE USERID = #{username} 93 | 94 | 95 | 96 | INSERT INTO ACCOUNT 97 | (EMAIL, FIRSTNAME, LASTNAME, STATUS, ADDR1, ADDR2, CITY, STATE, ZIP, COUNTRY, PHONE, USERID) 98 | VALUES 99 | (#{email}, #{firstName}, #{lastName}, #{status}, #{address1}, #{address2,jdbcType=VARCHAR}, #{city}, #{state}, #{zip}, #{country}, #{phone}, #{username}) 100 | 101 | 102 | 103 | 104 | 105 | 106 | UPDATE PROFILE SET 107 | LANGPREF = #{languagePreference}, 108 | FAVCATEGORY = #{favouriteCategoryId}, 109 | MYLISTOPT = #{listOptionValue}, 110 | BANNEROPT = #{bannerOptionValue} 111 | WHERE USERID = #{username} 112 | 113 | 114 | 115 | 116 | 117 | 118 | INSERT INTO PROFILE (LANGPREF, FAVCATEGORY, MYLISTOPT, BANNEROPT, USERID) 119 | VALUES (#{languagePreference}, #{favouriteCategoryId}, #{listOptionValue}, #{bannerOptionValue}, #{username}) 120 | 121 | 122 | 123 | UPDATE SIGNON SET PASSWORD = #{password} 124 | WHERE USERNAME = #{username} 125 | 126 | 127 | 128 | INSERT INTO SIGNON (PASSWORD,USERNAME) 129 | VALUES (#{password}, #{username}) 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/common/IncludeTop.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ page contentType="text/html;charset=UTF-8" language="java"%> 19 | <%@ taglib prefix="stripes" 20 | uri="http://stripes.sourceforge.net/stripes.tld"%> 21 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 22 | <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 23 | 24 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 35 | JPetStore Demo 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 130 | 131 |
-------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/order/ViewOrder.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | 3 | Copyright 2010-2022 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --%> 18 | <%@ include file="../common/IncludeTop.jsp"%> 19 | 20 | 23 | 24 |
25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 167 | 168 | 169 |
Order #${actionBean.order.orderId} 29 |
Payment Details
Card Type:
Card Number: * Fake 42 | number!
Expiry Date (MM/YYYY):
Billing Address
First name:
Last name:
Address 1:
Address 2:
City:
State:
Zip:
Country:
Shipping Address
First name:
Last name:
Address 1:
Address 2:
City:
State:
Zip:
Country:
Courier:
Status:
127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 143 | 153 | 154 | 155 | 157 | 159 | 160 | 161 | 162 | 164 | 165 |
Item IDDescriptionQuantityPriceTotal Cost
140 | 141 | ${lineItem.item.itemId} 142 | 144 | ${lineItem.item.attribute1} 145 | ${lineItem.item.attribute2} 146 | ${lineItem.item.attribute3} 147 | ${lineItem.item.attribute4} 148 | ${lineItem.item.attribute5} 149 | ${lineItem.item.product.name} 150 | 151 | {description unavailable} 152 | ${lineItem.quantity}$$
Total: $
166 |
170 | 171 |
172 | 173 | <%@ include file="../common/IncludeBottom.jsp"%> 174 | -------------------------------------------------------------------------------- /src/main/resources/database/jpetstore-hsqldb-schema.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2010-2022 the original author or authors. 3 | -- 4 | -- Licensed under the Apache License, Version 2.0 (the "License"); 5 | -- you may not use this file except in compliance with the License. 6 | -- You may obtain a copy of the License at 7 | -- 8 | -- https://www.apache.org/licenses/LICENSE-2.0 9 | -- 10 | -- Unless required by applicable law or agreed to in writing, software 11 | -- distributed under the License is distributed on an "AS IS" BASIS, 12 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | -- See the License for the specific language governing permissions and 14 | -- limitations under the License. 15 | -- 16 | 17 | create table supplier ( 18 | suppid int not null, 19 | name varchar(80) null, 20 | status varchar(2) not null, 21 | addr1 varchar(80) null, 22 | addr2 varchar(80) null, 23 | city varchar(80) null, 24 | state varchar(80) null, 25 | zip varchar(5) null, 26 | phone varchar(80) null, 27 | constraint pk_supplier primary key (suppid) 28 | ); 29 | 30 | create table signon ( 31 | username varchar(25) not null, 32 | password varchar(25) not null, 33 | constraint pk_signon primary key (username) 34 | ); 35 | 36 | create table account ( 37 | userid varchar(80) not null, 38 | email varchar(80) not null, 39 | firstname varchar(80) not null, 40 | lastname varchar(80) not null, 41 | status varchar(2) null, 42 | addr1 varchar(80) not null, 43 | addr2 varchar(40) null, 44 | city varchar(80) not null, 45 | state varchar(80) not null, 46 | zip varchar(20) not null, 47 | country varchar(20) not null, 48 | phone varchar(80) not null, 49 | constraint pk_account primary key (userid) 50 | ); 51 | 52 | create table profile ( 53 | userid varchar(80) not null, 54 | langpref varchar(80) not null, 55 | favcategory varchar(30), 56 | mylistopt int, 57 | banneropt int, 58 | constraint pk_profile primary key (userid) 59 | ); 60 | 61 | create table bannerdata ( 62 | favcategory varchar(80) not null, 63 | bannername varchar(255) null, 64 | constraint pk_bannerdata primary key (favcategory) 65 | ); 66 | 67 | create table orders ( 68 | orderid int not null, 69 | userid varchar(80) not null, 70 | orderdate date not null, 71 | shipaddr1 varchar(80) not null, 72 | shipaddr2 varchar(80) null, 73 | shipcity varchar(80) not null, 74 | shipstate varchar(80) not null, 75 | shipzip varchar(20) not null, 76 | shipcountry varchar(20) not null, 77 | billaddr1 varchar(80) not null, 78 | billaddr2 varchar(80) null, 79 | billcity varchar(80) not null, 80 | billstate varchar(80) not null, 81 | billzip varchar(20) not null, 82 | billcountry varchar(20) not null, 83 | courier varchar(80) not null, 84 | totalprice decimal(10,2) not null, 85 | billtofirstname varchar(80) not null, 86 | billtolastname varchar(80) not null, 87 | shiptofirstname varchar(80) not null, 88 | shiptolastname varchar(80) not null, 89 | creditcard varchar(80) not null, 90 | exprdate varchar(7) not null, 91 | cardtype varchar(80) not null, 92 | locale varchar(80) not null, 93 | constraint pk_orders primary key (orderid) 94 | ); 95 | 96 | create table orderstatus ( 97 | orderid int not null, 98 | linenum int not null, 99 | timestamp date not null, 100 | status varchar(2) not null, 101 | constraint pk_orderstatus primary key (orderid, linenum) 102 | ); 103 | 104 | create table lineitem ( 105 | orderid int not null, 106 | linenum int not null, 107 | itemid varchar(10) not null, 108 | quantity int not null, 109 | unitprice decimal(10,2) not null, 110 | constraint pk_lineitem primary key (orderid, linenum) 111 | ); 112 | 113 | create table category ( 114 | catid varchar(10) not null, 115 | name varchar(80) null, 116 | descn varchar(255) null, 117 | constraint pk_category primary key (catid) 118 | ); 119 | 120 | create table product ( 121 | productid varchar(10) not null, 122 | category varchar(10) not null, 123 | name varchar(80) null, 124 | descn varchar(255) null, 125 | constraint pk_product primary key (productid), 126 | constraint fk_product_1 foreign key (category) 127 | references category (catid) 128 | ); 129 | 130 | create index productCat on product (category); 131 | create index productName on product (name); 132 | 133 | create table item ( 134 | itemid varchar(10) not null, 135 | productid varchar(10) not null, 136 | listprice decimal(10,2) null, 137 | unitcost decimal(10,2) null, 138 | supplier int null, 139 | status varchar(2) null, 140 | attr1 varchar(80) null, 141 | attr2 varchar(80) null, 142 | attr3 varchar(80) null, 143 | attr4 varchar(80) null, 144 | attr5 varchar(80) null, 145 | constraint pk_item primary key (itemid), 146 | constraint fk_item_1 foreign key (productid) 147 | references product (productid), 148 | constraint fk_item_2 foreign key (supplier) 149 | references supplier (suppid) 150 | ); 151 | 152 | create index itemProd on item (productid); 153 | 154 | create table inventory ( 155 | itemid varchar(10) not null, 156 | qty int not null, 157 | constraint pk_inventory primary key (itemid) 158 | ); 159 | 160 | CREATE TABLE sequence 161 | ( 162 | name varchar(30) not null, 163 | nextid int not null, 164 | constraint pk_sequence primary key (name) 165 | ); 166 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/service/CatalogServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.service; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.mockito.Mockito.when; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.extension.ExtendWith; 26 | import org.mockito.InjectMocks; 27 | import org.mockito.Mock; 28 | import org.mockito.junit.jupiter.MockitoExtension; 29 | import org.mybatis.jpetstore.domain.Category; 30 | import org.mybatis.jpetstore.domain.Item; 31 | import org.mybatis.jpetstore.domain.Product; 32 | import org.mybatis.jpetstore.mapper.CategoryMapper; 33 | import org.mybatis.jpetstore.mapper.ItemMapper; 34 | import org.mybatis.jpetstore.mapper.ProductMapper; 35 | 36 | /** 37 | * @author Eduardo Macarron 38 | */ 39 | @ExtendWith(MockitoExtension.class) 40 | class CatalogServiceTest { 41 | 42 | @Mock(lenient = true) 43 | private ProductMapper productMapper; 44 | @Mock 45 | private CategoryMapper categoryMapper; 46 | @Mock 47 | private ItemMapper itemMapper; 48 | 49 | @InjectMocks 50 | private CatalogService catalogService; 51 | 52 | @Test 53 | void shouldCallTheSearchMapperTwice() { 54 | // given 55 | String keywords = "a b"; 56 | List l1 = new ArrayList<>(); 57 | l1.add(new Product()); 58 | List l2 = new ArrayList<>(); 59 | l2.add(new Product()); 60 | 61 | // when 62 | when(productMapper.searchProductList("%a%")).thenReturn(l1); 63 | when(productMapper.searchProductList("%b%")).thenReturn(l2); 64 | List r = catalogService.searchProductList(keywords); 65 | 66 | // then 67 | assertThat(r).hasSize(2); 68 | assertThat(r.get(0)).isSameAs(l1.get(0)); 69 | assertThat(r.get(1)).isSameAs(l2.get(0)); 70 | } 71 | 72 | @Test 73 | void shouldReturnCategoryList() { 74 | // given 75 | List expectedCategories = new ArrayList<>(); 76 | 77 | // when 78 | when(categoryMapper.getCategoryList()).thenReturn(expectedCategories); 79 | List categories = catalogService.getCategoryList(); 80 | 81 | // then 82 | assertThat(categories).isSameAs(expectedCategories); 83 | } 84 | 85 | @Test 86 | void shouldReturnCategory() { 87 | 88 | // given 89 | String categoryId = "C01"; 90 | Category expectedCategory = new Category(); 91 | 92 | // when 93 | when(categoryMapper.getCategory(categoryId)).thenReturn(expectedCategory); 94 | Category category = catalogService.getCategory(categoryId); 95 | 96 | // then 97 | assertThat(category).isSameAs(expectedCategory); 98 | 99 | } 100 | 101 | @Test 102 | void shouldReturnProduct() { 103 | 104 | // given 105 | String productId = "P01"; 106 | Product expectedProduct = new Product(); 107 | 108 | // when 109 | when(productMapper.getProduct(productId)).thenReturn(expectedProduct); 110 | Product product = catalogService.getProduct(productId); 111 | 112 | // then 113 | assertThat(product).isSameAs(expectedProduct); 114 | 115 | } 116 | 117 | @Test 118 | void shouldReturnProductList() { 119 | // given 120 | String categoryId = "C01"; 121 | List expectedProducts = new ArrayList<>(); 122 | 123 | // when 124 | when(productMapper.getProductListByCategory(categoryId)).thenReturn(expectedProducts); 125 | List products = catalogService.getProductListByCategory(categoryId); 126 | 127 | // then 128 | assertThat(products).isSameAs(expectedProducts); 129 | 130 | } 131 | 132 | @Test 133 | void shouldReturnItemList() { 134 | // given 135 | String productId = "P01"; 136 | List expectedItems = new ArrayList<>(); 137 | 138 | // when 139 | when(itemMapper.getItemListByProduct(productId)).thenReturn(expectedItems); 140 | List items = catalogService.getItemListByProduct(productId); 141 | 142 | // then 143 | assertThat(items).isSameAs(expectedItems); 144 | 145 | } 146 | 147 | @Test 148 | void shouldReturnItem() { 149 | 150 | // given 151 | String itemCode = "I01"; 152 | Item expectedItem = new Item(); 153 | 154 | // when 155 | when(itemMapper.getItem(itemCode)).thenReturn(expectedItem); 156 | Item item = catalogService.getItem(itemCode); 157 | 158 | // then 159 | assertThat(item).isSameAs(expectedItem); 160 | 161 | } 162 | 163 | @Test 164 | void shouldReturnTrueWhenExistStock() { 165 | 166 | // given 167 | String itemCode = "I01"; 168 | 169 | // when 170 | when(itemMapper.getInventoryQuantity(itemCode)).thenReturn(1); 171 | boolean result = catalogService.isItemInStock(itemCode); 172 | 173 | // then 174 | assertThat(result).isTrue(); 175 | 176 | } 177 | 178 | @Test 179 | void shouldReturnFalseWhenNotExistStock() { 180 | 181 | // given 182 | String itemCode = "I01"; 183 | 184 | // when 185 | when(itemMapper.getInventoryQuantity(itemCode)).thenReturn(0); 186 | boolean result = catalogService.isItemInStock(itemCode); 187 | 188 | // then 189 | assertThat(result).isFalse(); 190 | 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/mapper/ItemMapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.mapper; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.Comparator; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | import org.junit.jupiter.api.Test; 27 | import org.junit.jupiter.api.extension.ExtendWith; 28 | import org.mybatis.jpetstore.domain.Item; 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.jdbc.core.JdbcTemplate; 31 | import org.springframework.test.context.ContextConfiguration; 32 | import org.springframework.test.context.junit.jupiter.SpringExtension; 33 | import org.springframework.transaction.annotation.Transactional; 34 | 35 | @ExtendWith(SpringExtension.class) 36 | @ContextConfiguration(classes = MapperTestContext.class) 37 | @Transactional 38 | class ItemMapperTest { 39 | 40 | @Autowired 41 | private ItemMapper mapper; 42 | 43 | @Autowired 44 | private JdbcTemplate jdbcTemplate; 45 | 46 | @Test 47 | void getItemListByProduct() { 48 | // given 49 | String productId = "FI-SW-01"; 50 | 51 | // when 52 | List items = mapper.getItemListByProduct(productId); 53 | 54 | // then 55 | items.sort(Comparator.comparing(Item::getItemId)); 56 | assertThat(items).hasSize(2); 57 | assertThat(items.get(0).getItemId()).isEqualTo("EST-1"); 58 | assertThat(items.get(0).getListPrice()).isEqualTo(new BigDecimal("16.50")); 59 | assertThat(items.get(0).getUnitCost()).isEqualTo(new BigDecimal("10.00")); 60 | assertThat(items.get(0).getSupplierId()).isEqualTo(1); 61 | assertThat(items.get(0).getStatus()).isEqualTo("P"); 62 | assertThat(items.get(0).getAttribute1()).isEqualTo("Large"); 63 | assertThat(items.get(0).getAttribute2()).isNull(); 64 | assertThat(items.get(0).getAttribute3()).isNull(); 65 | assertThat(items.get(0).getAttribute4()).isNull(); 66 | assertThat(items.get(0).getAttribute5()).isNull(); 67 | assertThat(items.get(0).getProduct().getProductId()).isEqualTo("FI-SW-01"); 68 | assertThat(items.get(0).getProduct().getName()).isEqualTo("Angelfish"); 69 | assertThat(items.get(0).getProduct().getDescription()) 70 | .isEqualTo("Salt Water fish from Australia"); 71 | assertThat(items.get(0).getProduct().getCategoryId()).isEqualTo("FISH"); 72 | assertThat(items.get(1).getItemId()).isEqualTo("EST-2"); 73 | assertThat(items.get(1).getListPrice()).isEqualTo(new BigDecimal("16.50")); 74 | assertThat(items.get(1).getUnitCost()).isEqualTo(new BigDecimal("10.00")); 75 | assertThat(items.get(1).getSupplierId()).isEqualTo(1); 76 | assertThat(items.get(1).getStatus()).isEqualTo("P"); 77 | assertThat(items.get(1).getAttribute1()).isEqualTo("Small"); 78 | assertThat(items.get(1).getAttribute2()).isNull(); 79 | assertThat(items.get(1).getAttribute3()).isNull(); 80 | assertThat(items.get(1).getAttribute4()).isNull(); 81 | assertThat(items.get(1).getAttribute5()).isNull(); 82 | assertThat(items.get(1).getProduct().getProductId()).isEqualTo("FI-SW-01"); 83 | assertThat(items.get(1).getProduct().getName()).isEqualTo("Angelfish"); 84 | assertThat(items.get(1).getProduct().getDescription()) 85 | .isEqualTo("Salt Water fish from Australia"); 86 | assertThat(items.get(1).getProduct().getCategoryId()).isEqualTo("FISH"); 87 | } 88 | 89 | @Test 90 | void getItem() { 91 | // given 92 | String itemId = "EST-1"; 93 | 94 | // when 95 | Item item = mapper.getItem(itemId); 96 | 97 | // then 98 | assertThat(item.getItemId()).isEqualTo("EST-1"); 99 | assertThat(item.getListPrice()).isEqualTo(new BigDecimal("16.50")); 100 | assertThat(item.getUnitCost()).isEqualTo(new BigDecimal("10.00")); 101 | assertThat(item.getSupplierId()).isEqualTo(1); 102 | assertThat(item.getStatus()).isEqualTo("P"); 103 | assertThat(item.getAttribute1()).isEqualTo("Large"); 104 | assertThat(item.getAttribute2()).isNull(); 105 | assertThat(item.getAttribute3()).isNull(); 106 | assertThat(item.getAttribute4()).isNull(); 107 | assertThat(item.getAttribute5()).isNull(); 108 | assertThat(item.getProduct().getProductId()).isEqualTo("FI-SW-01"); 109 | assertThat(item.getProduct().getName()).isEqualTo("Angelfish"); 110 | assertThat(item.getProduct().getDescription()) 111 | .isEqualTo("Salt Water fish from Australia"); 112 | assertThat(item.getProduct().getCategoryId()).isEqualTo("FISH"); 113 | } 114 | 115 | @Test 116 | void getInventoryQuantity() { 117 | // given 118 | String itemId = "EST-1"; 119 | 120 | // when 121 | int quantity = mapper.getInventoryQuantity(itemId); 122 | 123 | // then 124 | assertThat(quantity).isEqualTo(10000); 125 | 126 | } 127 | 128 | @Test 129 | void updateInventoryQuantity() { 130 | // given 131 | String itemId = "EST-1"; 132 | Map params = new HashMap<>(); 133 | params.put("itemId", itemId); 134 | params.put("increment", 10); 135 | 136 | // when 137 | mapper.updateInventoryQuantity(params); 138 | 139 | // then 140 | Integer quantity = jdbcTemplate.queryForObject("SELECT QTY FROM inventory WHERE itemid = ?", Integer.class, itemId); 141 | assertThat(quantity).isEqualTo(9990); 142 | 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/jpetstore/domain/CartTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.mybatis.jpetstore.domain; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.Iterator; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | class CartTest { 26 | 27 | @Test 28 | void addItemWhenIsInStockIsTrue() { 29 | // given 30 | Cart cart = new Cart(); 31 | Item item = new Item(); 32 | item.setItemId("I01"); 33 | item.setListPrice(new BigDecimal("2.05")); 34 | 35 | // when 36 | cart.addItem(item, true); 37 | cart.addItem(item, true); 38 | 39 | // then 40 | assertThat(cart.getCartItemList().get(0).getItem()).isSameAs(item); 41 | assertThat(cart.getCartItemList().get(0).isInStock()).isTrue(); 42 | assertThat(cart.getCartItemList().get(0).getQuantity()).isEqualTo(2); 43 | assertThat(cart.getCartItemList().get(0).getTotal()).isEqualTo(new BigDecimal("4.10")); 44 | assertThat(cart.containsItemId("I01")).isTrue(); 45 | assertThat(cart.getNumberOfItems()).isEqualTo(1); 46 | { 47 | Iterator cartItems = cart.getCartItems(); 48 | assertThat(cartItems.next()).isNotNull(); 49 | assertThat(cartItems.hasNext()).isFalse(); 50 | } 51 | { 52 | Iterator cartItems = cart.getAllCartItems(); 53 | assertThat(cartItems.next()).isNotNull(); 54 | assertThat(cartItems.hasNext()).isFalse(); 55 | } 56 | } 57 | 58 | @Test 59 | void addItemWhenIsInStockIsFalse() { 60 | // given 61 | Cart cart = new Cart(); 62 | Item item = new Item(); 63 | item.setItemId("I01"); 64 | item.setListPrice(new BigDecimal("2.05")); 65 | 66 | // when 67 | cart.addItem(item, false); 68 | 69 | // then 70 | assertThat(cart.getCartItemList().get(0).getItem()).isSameAs(item); 71 | assertThat(cart.getCartItemList().get(0).isInStock()).isFalse(); 72 | assertThat(cart.getCartItemList().get(0).getQuantity()).isEqualTo(1); 73 | assertThat(cart.getCartItemList().get(0).getTotal()).isEqualTo(new BigDecimal("2.05")); 74 | } 75 | 76 | @Test 77 | void removeItemByIdWhenItemNotFound() { 78 | // given 79 | Cart cart = new Cart(); 80 | 81 | // when 82 | Item item = cart.removeItemById("I01"); 83 | 84 | // then 85 | assertThat(item).isNull(); 86 | assertThat(cart.containsItemId("I01")).isFalse(); 87 | assertThat(cart.getNumberOfItems()).isEqualTo(0); 88 | assertThat(cart.getCartItems().hasNext()).isFalse(); 89 | assertThat(cart.getAllCartItems().hasNext()).isFalse(); 90 | } 91 | 92 | @Test 93 | void removeItemByIdWhenItemFound() { 94 | // given 95 | Cart cart = new Cart(); 96 | Item item = new Item(); 97 | item.setItemId("I01"); 98 | item.setListPrice(new BigDecimal("2.05")); 99 | cart.addItem(item, true); 100 | 101 | // when 102 | Item removedItem = cart.removeItemById("I01"); 103 | 104 | // then 105 | assertThat(removedItem).isSameAs(item); 106 | assertThat(cart.getCartItemList()).isEmpty(); 107 | } 108 | 109 | @Test 110 | void incrementQuantityByItemId() { 111 | // given 112 | Cart cart = new Cart(); 113 | Item item = new Item(); 114 | item.setItemId("I01"); 115 | item.setListPrice(new BigDecimal("2.05")); 116 | cart.addItem(item, true); 117 | 118 | // when 119 | cart.incrementQuantityByItemId("I01"); 120 | cart.incrementQuantityByItemId("I01"); 121 | 122 | // then 123 | assertThat(cart.getCartItemList().get(0).getItem()).isSameAs(item); 124 | assertThat(cart.getCartItemList().get(0).isInStock()).isTrue(); 125 | assertThat(cart.getCartItemList().get(0).getQuantity()).isEqualTo(3); 126 | assertThat(cart.getCartItemList().get(0).getTotal()).isEqualTo(new BigDecimal("6.15")); 127 | } 128 | 129 | @Test 130 | void setQuantityByItemId() { 131 | // given 132 | Cart cart = new Cart(); 133 | Item item = new Item(); 134 | item.setItemId("I01"); 135 | item.setListPrice(new BigDecimal("2.05")); 136 | cart.addItem(item, true); 137 | 138 | // when 139 | cart.setQuantityByItemId("I01", 10); 140 | 141 | // then 142 | assertThat(cart.getCartItemList().get(0).getItem()).isSameAs(item); 143 | assertThat(cart.getCartItemList().get(0).isInStock()).isTrue(); 144 | assertThat(cart.getCartItemList().get(0).getQuantity()).isEqualTo(10); 145 | assertThat(cart.getCartItemList().get(0).getTotal()).isEqualTo(new BigDecimal("20.50")); 146 | } 147 | 148 | @Test 149 | void getSubTotalWhenItemIsEmpty() { 150 | // given 151 | Cart cart = new Cart(); 152 | 153 | // when 154 | BigDecimal subTotal = cart.getSubTotal(); 155 | 156 | // then 157 | assertThat(subTotal).isEqualTo(BigDecimal.ZERO); 158 | 159 | } 160 | 161 | @Test 162 | void getSubTotalWhenItemIsExist() { 163 | // given 164 | Cart cart = new Cart(); 165 | { 166 | Item item = new Item(); 167 | item.setItemId("I01"); 168 | item.setListPrice(new BigDecimal("2.05")); 169 | cart.addItem(item, true); 170 | cart.setQuantityByItemId("I01", 5); 171 | } 172 | { 173 | Item item = new Item(); 174 | item.setItemId("I02"); 175 | item.setListPrice(new BigDecimal("3.06")); 176 | cart.addItem(item, true); 177 | cart.setQuantityByItemId("I02", 6); 178 | } 179 | 180 | // when 181 | BigDecimal subTotal = cart.getSubTotal(); 182 | 183 | // then 184 | assertThat(subTotal).isEqualTo(new BigDecimal("28.61")); 185 | } 186 | 187 | } 188 | --------------------------------------------------------------------------------