Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
assignments_new
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Suresh Kumar
assignments_new
Commits
a541f1ef
Commit
a541f1ef
authored
Aug 12, 2022
by
Suresh Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Internee Test
parent
6c965654
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
584 additions
and
2 deletions
+584
-2
README.md
README.md
+0
-2
pom.xml
pom.xml
+84
-0
CartController.java
...java/com/shopingCardSystem/Controller/CartController.java
+44
-0
ItemController.java
...java/com/shopingCardSystem/Controller/ItemController.java
+48
-0
DemoApplication.java
src/main/java/com/shopingCardSystem/DemoApplication.java
+21
-0
Cart.java
src/main/java/com/shopingCardSystem/Model/Cart.java
+40
-0
Item.java
src/main/java/com/shopingCardSystem/Model/Item.java
+32
-0
CartRepository.java
...java/com/shopingCardSystem/Repository/CartRepository.java
+10
-0
ItemReository.java
.../java/com/shopingCardSystem/Repository/ItemReository.java
+10
-0
CartService.java
src/main/java/com/shopingCardSystem/Service/CartService.java
+22
-0
CartServiceImpl.java
...n/java/com/shopingCardSystem/Service/CartServiceImpl.java
+48
-0
ItemService.java
src/main/java/com/shopingCardSystem/Service/ItemService.java
+23
-0
ItemServiceImpl.java
...n/java/com/shopingCardSystem/Service/ItemServiceImpl.java
+47
-0
application.properties
src/main/resources/application.properties
+9
-0
DemoApplicationTests.java
...test/java/com/shopingCardSystem/DemoApplicationTests.java
+13
-0
CartServiceImplTest.java
...va/com/shopingCardSystem/Service/CartServiceImplTest.java
+66
-0
ItemServiceImplTest.java
...va/com/shopingCardSystem/Service/ItemServiceImplTest.java
+67
-0
No files found.
README.md
deleted
100644 → 0
View file @
6c965654
# assignments_new
pom.xml
0 → 100644
View file @
a541f1ef
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.7.2
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>
com.shopingCardSystem
</groupId>
<artifactId>
demo
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
demo
</name>
<description>
Shoping Card System
</description>
<properties>
<java.version>
1.8
</java.version>
<junit-platform.version>
5.5.2
</junit-platform.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<scope>
runtime
</scope>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
<version>
${junit-jupiter.version}
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
src/main/java/com/shopingCardSystem/Controller/CartController.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Controller
;
import
java.util.List
;
import
com.shopingCardSystem.Model.Cart
;
import
org.springframework.web.bind.annotation.*
;
import
com.shopingCardSystem.Service.CartServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
@RestController
@RequestMapping
(
"/cartRecords"
)
public
class
CartController
{
@Autowired
private
CartServiceImpl
cartService
;
@GetMapping
(
"/carts"
)
public
List
<
Cart
>
getAllCart
(){
return
cartService
.
getAllItems
();
}
@GetMapping
(
"/{cartId}"
)
public
Cart
getCardById
(
@PathVariable
(
"cartId"
)
int
cartId
){
Cart
cart
=
cartService
.
getCartgetById
(
cartId
);
return
cart
;
}
@PostMapping
(
"/cart"
)
public
Cart
addCart
(
@RequestBody
Cart
cart
){
cartService
.
addCart
(
cart
);
return
cart
;
}
@PutMapping
(
"/{cartId}"
)
public
Cart
updateCardById
(
@RequestBody
Cart
cart
,
@PathVariable
(
"cartId"
)
int
cartId
){
cartService
.
updateCartById
(
cart
,
cartId
);
return
cart
;
}
@DeleteMapping
(
"/{cartId}"
)
public
void
deleteCard
(
@PathVariable
(
"cartId"
)
int
cardId
){
cartService
.
deleteCardById
(
cardId
);
}
}
\ No newline at end of file
src/main/java/com/shopingCardSystem/Controller/ItemController.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Controller
;
import
java.util.List
;
import
com.shopingCardSystem.Model.Item
;
import
com.shopingCardSystem.Service.ItemServiceImpl
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
@RestController
@RequestMapping
(
"/itemRecords"
)
public
class
ItemController
{
@Autowired
private
ItemServiceImpl
itemService
;
@GetMapping
(
"/items"
)
public
List
<
Item
>
getAllItems
(){
return
itemService
.
getAllItems
();
}
@GetMapping
(
"/{itemId}"
)
public
Item
getItemById
(
@PathVariable
(
"itemId"
)
int
itemId
){
Item
item
=
this
.
itemService
.
getItemById
(
itemId
);
return
item
;
}
@PostMapping
(
"/item"
)
public
Item
addItem
(
@RequestBody
Item
item
){
this
.
itemService
.
addItem
(
item
);
return
item
;
}
@PutMapping
(
"{itemId}"
)
public
Item
updateItemById
(
@RequestBody
Item
item
,
@PathVariable
(
"itemId"
)
int
itemId
){
itemService
.
updateItemById
(
item
,
itemId
);
return
item
;
}
@DeleteMapping
(
"{itemId}"
)
public
void
deleteById
(
@PathVariable
(
"itemId"
)
int
itemId
){
this
.
itemService
.
deleteItemById
(
itemId
);
}
}
src/main/java/com/shopingCardSystem/DemoApplication.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
;
import
com.shopingCardSystem.Model.Cart
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@SpringBootApplication
public
class
DemoApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
DemoApplication
.
class
,
args
);
System
.
out
.
println
(
"Project Started...........!!!"
);
}
}
src/main/java/com/shopingCardSystem/Model/Cart.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Model
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.ToString
;
import
java.util.List
;
import
javax.persistence.*
;
@Getter
@Setter
@ToString
@NoArgsConstructor
@Entity
@Table
(
name
=
"cart"
)
public
class
Cart
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
int
cartId
;
private
int
itemCount
;
private
double
grandTotal
;
private
double
totalDiscount
;
@OneToMany
(
cascade
=
CascadeType
.
ALL
)
@JoinColumn
(
name
=
"cartId"
)
private
List
<
Item
>
items
;
public
Cart
(
int
cartId
,
int
itemCount
,
double
grandTotal
,
double
totalDiscount
){
this
.
cartId
=
cartId
;
this
.
itemCount
=
itemCount
;
this
.
grandTotal
=
grandTotal
;
this
.
totalDiscount
=
totalDiscount
;
}
}
src/main/java/com/shopingCardSystem/Model/Item.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Model
;
import
lombok.*
;
import
javax.persistence.*
;
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table
(
name
=
"items"
)
public
class
Item
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
int
itemId
;
private
double
discount
;
private
double
price
;
private
int
quantity
;
private
long
upc
;
}
src/main/java/com/shopingCardSystem/Repository/CartRepository.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Repository
;
import
com.shopingCardSystem.Model.Cart
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
CartRepository
extends
CrudRepository
<
Cart
,
Integer
>
{
Cart
findById
(
int
cartId
);
}
src/main/java/com/shopingCardSystem/Repository/ItemReository.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Repository
;
import
com.shopingCardSystem.Model.Item
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
ItemReository
extends
CrudRepository
<
Item
,
Integer
>
{
Item
findById
(
int
itemId
);
}
src/main/java/com/shopingCardSystem/Service/CartService.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Service
;
import
com.shopingCardSystem.Model.Cart
;
import
java.util.List
;
public
interface
CartService
{
public
List
<
Cart
>
getAllItems
();
public
Cart
getCartgetById
(
int
cartId
);
public
Cart
addCart
(
Cart
cart
);
public
Cart
updateCartById
(
Cart
cart
,
int
cartId
);
public
void
deleteCardById
(
int
cartId
);
}
src/main/java/com/shopingCardSystem/Service/CartServiceImpl.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Service
;
import
java.util.List
;
import
com.shopingCardSystem.Model.Cart
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
com.shopingCardSystem.Repository.CartRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
@Component
@Service
public
class
CartServiceImpl
implements
CartService
{
@Autowired
private
CartRepository
cartRepository
;
@Override
public
List
<
Cart
>
getAllItems
()
{
List
<
Cart
>
list
=
(
List
<
Cart
>)
this
.
cartRepository
.
findAll
();
return
list
;
}
@Override
public
Cart
getCartgetById
(
int
cartId
)
{
Cart
cart
=
null
;
cart
=
cartRepository
.
findById
(
cartId
);
return
cart
;
}
@Override
public
Cart
addCart
(
Cart
cart
)
{
cartRepository
.
save
(
cart
);
return
cart
;
}
@Override
public
Cart
updateCartById
(
Cart
cart
,
int
cartId
)
{
cart
.
setCartId
(
cartId
);
cartRepository
.
save
(
cart
);
return
cart
;
}
@Override
public
void
deleteCardById
(
int
cartId
)
{
cartRepository
.
deleteById
(
cartId
);
}
}
src/main/java/com/shopingCardSystem/Service/ItemService.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Service
;
import
java.util.List
;
import
com.shopingCardSystem.Model.Item
;
public
interface
ItemService
{
public
List
<
Item
>
getAllItems
();
public
Item
getItemById
(
int
itemId
);
public
Item
addItem
(
Item
item
);
public
Item
updateItemById
(
Item
item
,
int
itemId
);
public
void
deleteItemById
(
int
itemId
);
}
src/main/java/com/shopingCardSystem/Service/ItemServiceImpl.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Service
;
import
com.shopingCardSystem.Model.Item
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.shopingCardSystem.Repository.ItemReository
;
@Service
public
class
ItemServiceImpl
implements
ItemService
{
@Autowired
private
ItemReository
itemReository
;
@Override
public
List
<
Item
>
getAllItems
()
{
List
<
Item
>
list
=
(
List
<
Item
>)
itemReository
.
findAll
();
return
list
;
}
@Override
public
Item
getItemById
(
int
itemId
)
{
Item
item
=
null
;
item
=
itemReository
.
findById
(
itemId
);
return
item
;
}
// @Override
public
Item
addItem
(
Item
item
)
{
itemReository
.
save
(
item
);
return
item
;
}
@Override
public
Item
updateItemById
(
Item
item
,
int
itemId
)
{
item
.
setItemId
(
itemId
);
itemReository
.
save
(
item
);
return
item
;
}
@Override
public
void
deleteItemById
(
int
itemId
)
{
itemReository
.
deleteById
(
itemId
);
}
}
src/main/resources/application.properties
0 → 100644
View file @
a541f1ef
server.port
=
8086
spring.datasource.name
=
InterneeTest
spring.datasource.url
=
jdbc:mysql://localhost:3306/InterneeTest?characterEncoding=utf8
spring.datasource.username
=
root
spring.datasource.password
=
nisum123
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect
=
org.hibernate.dialect.MySQL55Dialect
spring.jpa.generate-ddl
=
true
spring.jpa.hibernate.ddl-auto
=
update
src/test/java/com/shopingCardSystem/DemoApplicationTests.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
DemoApplicationTests
{
@Test
void
contextLoads
()
{
}
}
src/test/java/com/shopingCardSystem/Service/CartServiceImplTest.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Service
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.InjectMocks
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.Test
;
import
java.util.stream.Collectors
;
import
static
org
.
mockito
.
Mockito
.*;
import
com.shopingCardSystem.Model.Cart
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
com.shopingCardSystem.Repository.CartRepository
;
@ExtendWith
(
MockitoExtension
.
class
)
class
CartServiceImplTest
{
@InjectMocks
private
CartServiceImpl
cartService
;
@Mock
private
CartRepository
cartRepository
;
@Test
public
void
getAllItems
()
{
when
(
cartRepository
.
findAll
()).
thenReturn
(
Stream
.
of
(
new
Cart
(
1
,
255
,
54
,
50
),
new
Cart
(
2
,
30
,
20
,
20
)).
collect
(
Collectors
.
toList
()));
assertEquals
(
2
,
cartService
.
getAllItems
().
size
());
}
@Test
void
getCartgetById
()
{
Cart
cart
=
new
Cart
(
3
,
222
,
40
,
15
);
when
(
cartRepository
.
findById
(
3
)).
thenReturn
(
cart
);
Cart
cartResult
=
cartService
.
getCartgetById
(
3
);
assertEquals
(
cart
,
cartResult
);
}
@Test
void
addCart
()
{
Cart
cart
=
new
Cart
(
3
,
222
,
40
,
15
);
when
(
cartRepository
.
save
(
cart
)).
thenReturn
(
cart
);
Cart
cartResult
=
cartService
.
addCart
(
cart
);
assertEquals
(
cart
,
cartResult
);
}
@Test
void
updateCartById
()
{
Cart
cart
=
new
Cart
(
4
,
332
,
50
,
45
);
Mockito
.
when
(
cartRepository
.
save
(
cart
)).
thenReturn
(
null
);
cart
.
setItemCount
(
443
);
Mockito
.
when
(
cartRepository
.
save
(
cart
)).
thenReturn
(
cart
);
assertEquals
(
cart
,
cartService
.
updateCartById
(
cart
,
cart
.
getCartId
()));
}
@Test
void
deleteCardById
()
{
Cart
cart
=
new
Cart
(
5
,
225
,
60
,
30
);
cartService
.
deleteCardById
(
cart
.
getCartId
());
verify
(
cartRepository
,
times
(
1
)).
deleteById
(
5
);
}
}
\ No newline at end of file
src/test/java/com/shopingCardSystem/Service/ItemServiceImplTest.java
0 → 100644
View file @
a541f1ef
package
com
.
shopingCardSystem
.
Service
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.InjectMocks
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.Test
;
import
java.util.stream.Collectors
;
import
static
org
.
mockito
.
Mockito
.*;
import
com.shopingCardSystem.Model.Item
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
com.shopingCardSystem.Repository.ItemReository
;
@ExtendWith
(
MockitoExtension
.
class
)
class
ItemServiceImplTest
{
@InjectMocks
private
ItemServiceImpl
itemService
;
@Mock
private
ItemReository
itemReository
;
@Test
public
void
getAllItems
()
{
when
(
itemReository
.
findAll
()).
thenReturn
(
Stream
.
of
(
new
Item
(
1
,
5
,
333
,
500
,
20
),
new
Item
(
2
,
3
,
343
,
1000
,
30
)).
collect
(
Collectors
.
toList
()));
assertEquals
(
2
,
itemService
.
getAllItems
().
size
());
}
@Test
void
getItemById
()
{
Item
item
=
new
Item
(
3
,
4
,
555
,
1000
,
40
);
when
(
itemReository
.
findById
(
3
)).
thenReturn
(
item
);
Item
itemResult
=
itemService
.
getItemById
(
3
);
assertEquals
(
item
,
itemResult
);
}
@Test
void
addItem
()
{
Item
item1
=
new
Item
(
5
,
5
,
2000
,
666
,
20
);
when
(
itemReository
.
save
(
item1
)).
thenReturn
(
item1
);
Item
itemResult
=
itemService
.
addItem
(
item1
);
assertEquals
(
item1
,
itemResult
);
}
@Test
void
updateItemById
()
{
Item
item2
=
new
Item
(
5
,
5
,
2000
,
666
,
20
);
Mockito
.
when
(
itemReository
.
save
(
item2
)).
thenReturn
(
null
);
item2
.
setDiscount
(
10
);
Mockito
.
when
(
itemReository
.
save
(
item2
)).
thenReturn
(
item2
);
assertEquals
(
item2
,
itemService
.
updateItemById
(
item2
,
item2
.
getItemId
()));
}
@Test
void
deleteItemById
()
{
Item
item
=
new
Item
(
6
,
5
,
6000
,
100
,
25
);
itemService
.
deleteItemById
(
item
.
getItemId
());
verify
(
itemReository
,
times
(
1
)).
deleteById
(
6
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment