Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create DataAccess Objects which will hold the listing data structures Singleton DTO DAO DAO file DataAccesObject.java package dao; import dto.BaseDto; import java.util.List; public interface DataAccessObject
Create DataAccess Objects which will hold the listing data structures
-
Singleton
-
DTO
-
DAO
DAO file
DataAccesObject.java
package dao; import dto.BaseDto; import java.util.List; public interface DataAccessObject{ static DataAccessObject getInstance(){ throw new RuntimeException("not implemented"); } T put(T item); List getItems(); void delete(String id); }
ItemDao.java
package dao; import dto.ItemDto; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class ItemDao implements DataAccessObject{ public static ItemDao getInstance(){ return null; } private ItemDao(){ } @Override public ItemDto put(ItemDto item) { return null; } @Override public List getItems() { return null; } @Override public void delete(String id) { } }
DTO file
BaseDto.java
package dto; public class BaseDto { public final String entity_id; public BaseDto(String entity_id) { this.entity_id = entity_id; } }
ItemDto.java
package dto; public class ItemDto extends BaseDto { public String description; public String type; public Integer price; public String title; public ItemDto(String id, String description, String type, Integer price, String title) { super(id); this.description = description; this.type = type; this.price = price; this.title = title; } public ItemDto(String description, String type, Integer price, String title) { super(null); this.description = description; this.type = type; this.price = price; this.title = title; } }
ResonseDto.java
package dto; import java.util.Date; import java.util.List; public class ResponseDto{ public final Date date; public final List items; public final Boolean success; public ResponseDto(Date date, List items, Boolean success) { this.date = date; this.items = items; this.success = success; } }
Test
DaoTests.java
package dao; import dto.ItemDto; import org.testng.Assert; import org.testng.annotations.Test; public class DaoTests { @Test public void testDaos(){ ItemDao itemDao = ItemDao.getInstance(); Assert.assertTrue(DataAccessObject.class.isAssignableFrom(itemDao.getClass())); ItemDto itemDto = new ItemDto(null, null, null, null); itemDao.put(itemDto); Assert.assertEquals(itemDao.getItems().size(), 1); Assert.assertNotNull(itemDao.getItems().get(0).entity_id); String id = itemDao.getItems().get(0).entity_id; itemDao.delete(id); Assert.assertEquals(itemDao.getItems().size(), 0); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started