Search in sources :

Example 51 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class StockUnitEaoIT method testFindByIdentifierAndStock.

@Test
public void testFindByIdentifierAndStock() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0, "TEEEEEEEEEEEEEEEST");
    em.persist(s);
    StockLocation sl = new StockLocation("Lagerplatz");
    s.addStockLocation(sl);
    StockUnit s1 = new StockUnit("G1", 1);
    s1.setRefurbishId("23");
    StockUnit s2 = new StockUnit("G2", 2);
    s2.setRefurbishId("42");
    s.addUnit(s1, sl);
    s.addUnit(s2, sl);
    em.persist(new Stock(1, "TEEEEEEEEST"));
    utx.commit();
    int id1 = s1.getId();
    int id2 = s2.getId();
    assertFalse(id1 == id2);
    s1 = sus.findByUniqueUnitId(1);
    s2 = sus.findByUniqueUnitId(2);
    assertThat(s1).isNotNull();
    assertThat(s2).isNotNull();
    assertEquals(id1, s1.getId());
    assertEquals(id2, s2.getId());
    List<StockUnit> units = sus.findByStockId(s.getId());
    assertEquals(2, units.size());
    s1 = sus.findByRefurbishId("23");
    s2 = sus.findByRefurbishId("42");
    assertNotNull(s1);
    assertNotNull(s2);
    assertEquals(id1, s1.getId());
    assertEquals(id2, s2.getId());
    assertNull(sus.findByRefurbishId("123"));
    assertNull(sus.findByRefurbishId(null));
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Example 52 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class StockUnitEaoIT method testFindByNoTransaction.

@Test
public void testFindByNoTransaction() throws Exception {
    utx.begin();
    em.joinTransaction();
    Stock s = new Stock(0, "TEEEEEEEEEEEEEEST");
    em.persist(s);
    StockLocation sl = new StockLocation("Lagerplatz");
    s.addStockLocation(sl);
    StockUnit s1 = new StockUnit("G1", 1);
    StockUnit s2 = new StockUnit("G2", 2);
    StockUnit s3 = new StockUnit("G3", 3);
    StockUnit s4 = new StockUnit("G4", 4);
    s.addUnit(s1, sl);
    s.addUnit(s2, sl);
    s.addUnit(s3, sl);
    s.addUnit(s4, sl);
    em.persist(s);
    em.persist(new Stock(1, "TEEEEEEEEEST2"));
    LogicTransaction lt = new LogicTransaction();
    lt.setDossierId(1);
    lt.add(s4);
    em.persist(lt);
    StockTransaction st = new StockTransaction(StockTransactionType.TRANSFER);
    st.setSource(s);
    st.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    em.persist(st);
    st.addPosition(new StockTransactionPosition(s1));
    utx.commit();
    List<StockUnit> sts = sus.findByNoTransaction();
    assertEquals(2, sts.size());
}
Also used : StockLocation(eu.ggnet.dwoss.stock.ee.entity.StockLocation) StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 53 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class ValidationTest method testStockUnit.

@Test
public void testStockUnit() {
    StockUnit su = new StockUnit("Bla", 0);
    Set<? extends ConstraintViolation> violations = validator.validate(su);
    if (violations.isEmpty())
        fail("No violation, but StockUnit has neither Stock nor Position");
    Stock s = new Stock(1, "Teststock");
    su.setStock(s);
    violations = validator.validate(su);
    if (!violations.isEmpty())
        fail("Violation, but StockUnit has Stock. msg: " + buildMessage(violations));
    su.setStock(null);
    violations = validator.validate(su);
    if (violations.isEmpty())
        fail("No violation, but StockUnit has neither Stock nor Position");
    StockTransactionPosition stp = new StockTransactionPosition(su);
    if (validator.validate(su).isEmpty())
        fail("No violation, but StockUnit has invalid Position");
    StockTransaction t = new StockTransaction();
    t.addPosition(stp);
    if (validator.validate(su).isEmpty())
        fail("No violation, but StockTransaction is still invalid (no status, no type)");
    t.addStatus(new StockTransactionStatus(StockTransactionStatusType.PREPARED, new Date()));
    if (validator.validate(su).isEmpty())
        fail("No violation, but StockTransaction is still invalid (no type)");
    t.setType(StockTransactionType.TRANSFER);
    violations = validator.validate(su);
    if (!violations.isEmpty())
        fail("Violation, but StockUnit has valid Position and Transaction. msg: " + buildMessage(violations));
    su.setStock(s);
    violations = validator.validate(su);
    if (!violations.isEmpty())
        fail("Violation, Special Case: StockUnit has Stock and Transaction(Prepared) which is ok. msg: " + buildMessage(violations));
    t.addStatus(new StockTransactionStatus(StockTransactionStatusType.COMMISSIONED, new Date()));
    if (validator.validate(su).isEmpty())
        fail("No violation, but now StockUnit has Stock and StockTransaction( not prepared), which is not ok.");
}
Also used : StockTransactionStatus(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus) StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Date(java.util.Date) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 54 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class CreateSelectionTryout method tryout.

@Test
public void tryout() throws InterruptedException {
    JButton b = new JButton("Press to close");
    b.setPreferredSize(new Dimension(200, 50));
    CountDownLatch l = new CountDownLatch(1);
    b.addActionListener(e -> {
        l.countDown();
    });
    Dl.remote().add(StockAgent.class, new StockAgent() {

        @Override
        public <T> List<T> findAll(Class<T> entityClass) {
            if (entityClass.equals(Stock.class))
                return (List<T>) Arrays.asList(new Stock(0, "Rotes Lager"), new Stock(1, "Blaues Lager"));
            return null;
        }

        // <editor-fold defaultstate="collapsed" desc="Unused Methodes">
        @Override
        public StockUnit findStockUnitByUniqueUnitIdEager(Integer uniqueUnitId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockUnit findStockUnitByRefurbishIdEager(String refurbishId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockUnit> findStockUnitsByRefurbishIdEager(List<String> refurbishIds) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T persist(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T merge(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> void delete(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockTransaction findOrCreateRollInTransaction(int stockId, String userName, String comment) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> long count(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAll(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    UiCore.startSwing(() -> b);
    Ui.exec(() -> {
        Ui.build().fxml().eval(CreateSelectionController.class).opt().ifPresent(System.out::println);
    });
    l.await();
}
Also used : JButton(javax.swing.JButton) Dimension(java.awt.Dimension) CountDownLatch(java.util.concurrent.CountDownLatch) StockTransactionType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionType) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) LockModeType(javax.persistence.LockModeType) List(java.util.List) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Test(org.junit.Test)

Example 55 with StockUnit

use of eu.ggnet.dwoss.stock.ee.entity.StockUnit in project dwoss by gg-net.

the class CreateSimpleActionTryout method tryout.

@Test
public void tryout() throws InterruptedException {
    JPanel p = new JPanel();
    JButton b = new JButton("Press to close");
    b.setPreferredSize(new Dimension(200, 50));
    CountDownLatch l = new CountDownLatch(1);
    b.addActionListener(e -> {
        l.countDown();
    });
    p.add(new JButton(new CreateSimpleAction()));
    p.add(b);
    Dl.remote().add(StockAgent.class, new StockAgent() {

        @Override
        public <T> List<T> findAll(Class<T> entityClass) {
            if (entityClass.equals(Stock.class))
                return (List<T>) Arrays.asList(new Stock(0, "Rotes Lager"), new Stock(1, "Blaues Lager"));
            return null;
        }

        @Override
        public List<StockUnit> findStockUnitsByRefurbishIdEager(List<String> refurbishIds) {
            if (refurbishIds.contains("1")) {
                Stock s = new Stock(0, "Lager1");
                StockUnit s1 = new StockUnit("1", "Gerät Eins", 1);
                s1.setStock(s);
                return Arrays.asList(s1);
            }
            return Collections.EMPTY_LIST;
        }

        // <editor-fold defaultstate="collapsed" desc="Unused Methodes">
        @Override
        public StockUnit findStockUnitByUniqueUnitIdEager(Integer uniqueUnitId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockUnit findStockUnitByRefurbishIdEager(String refurbishId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T persist(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T merge(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> void delete(T t) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StockTransaction findOrCreateRollInTransaction(int stockId, String userName, String comment) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> long count(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAll(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> List<T> findAllEager(Class<T> entityClass, int start, int amount) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findById(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public <T> T findByIdEager(Class<T> entityClass, Object id, LockModeType lockModeType) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    Dl.remote().add(StockTransactionProcessor.class, new StockTransactionProcessor() {

        @Override
        public SortedMap<Integer, String> perpareTransfer(List<StockUnit> stockUnits, int destinationStockId, String arranger, String comment) throws UserInfoException {
            SortedMap<Integer, String> r = new TreeMap<>();
            r.put(1, "1");
            return r;
        }

        // <editor-fold defaultstate="collapsed" desc="Unused Methodes">
        @Override
        public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void cancel(StockTransaction transaction, String arranger, String comment) throws UserInfoException {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void commission(List<StockTransaction> transactions, String picker, String deliverer) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void receive(List<StockTransaction> transactions, String deliverer, String reciever) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void removeFromPreparedTransaction(String refurbishId, String arranger, String comment) throws UserInfoException {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    Guardian guardianMock = mock(Guardian.class);
    given(guardianMock.getUsername()).willAnswer(i -> "Testuser");
    Dl.local().add(Guardian.class, guardianMock);
    UiCore.startSwing(() -> p);
    l.await();
}
Also used : JPanel(javax.swing.JPanel) JButton(javax.swing.JButton) StockTransactionType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionType) Guardian(eu.ggnet.saft.core.auth.Guardian) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) StockTransactionStatusType(eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatusType) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction) Dimension(java.awt.Dimension) CountDownLatch(java.util.concurrent.CountDownLatch) StockAgent(eu.ggnet.dwoss.stock.ee.StockAgent) LockModeType(javax.persistence.LockModeType) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) CreateSimpleAction(eu.ggnet.dwoss.stock.transactions.CreateSimpleAction) StockTransactionProcessor(eu.ggnet.dwoss.stock.ee.StockTransactionProcessor) Stock(eu.ggnet.dwoss.stock.ee.entity.Stock) Test(org.junit.Test)

Aggregations

StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)63 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)29 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)27 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)22 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)20 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)20 Test (org.junit.Test)19 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)18 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)13 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)11 StockAgent (eu.ggnet.dwoss.stock.ee.StockAgent)9 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)8 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)6 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)6 java.util (java.util)6 Inject (javax.inject.Inject)6 StockTransactionStatus (eu.ggnet.dwoss.stock.ee.entity.StockTransactionStatus)5