Skip to content

Commit

Permalink
ProductsToPickRowsDataFactoryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Sep 19, 2019
1 parent c023a96 commit c877bf3
Show file tree
Hide file tree
Showing 3 changed files with 472 additions and 30 deletions.
68 changes: 38 additions & 30 deletions pom.xml
@@ -1,5 +1,7 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -8,7 +10,8 @@
<version>[1,10.0.0]</version> <!-- we need the range during the jenkins build -->
</parent>

<!-- FRESH-271: we need an explicit version here, otherwise versions-maven-plugin can't set it to another version -->
<!-- FRESH-271: we need an explicit version here, otherwise versions-maven-plugin
can't set it to another version -->
<version>10.0.0</version>

<groupId>de.metas.ui.web</groupId>
Expand All @@ -18,9 +21,8 @@

<spring-boot.version>1.5.3.RELEASE</spring-boot.version>

<!-- See http://www.mojohaus.org/versions-maven-plugin/examples/update-properties.html
and http://stackoverflow.com/questions/3628471/maven-versions-plugin-not-picking-up-properties-from-parent
-->
<!-- See http://www.mojohaus.org/versions-maven-plugin/examples/update-properties.html
and http://stackoverflow.com/questions/3628471/maven-versions-plugin-not-picking-up-properties-from-parent -->
<metasfresh.version>[1,10.0.0]</metasfresh.version>

</properties>
Expand Down Expand Up @@ -49,20 +51,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<!-- TODO: enable this dependency when we will really implement spring security -->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
-->


<!-- TODO: enable this dependency when we will really implement spring
security -->
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> -->

<!-- see http://codecentric.github.io/spring-boot-admin/1.5.0/#client-applications -->
<!--
there are exclusions to avoid dependency version convergence issues
(i.e. to satisfy the enforcer plugin)
-->
<!-- there are exclusions to avoid dependency version convergence issues
(i.e. to satisfy the enforcer plugin) -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
Expand Down Expand Up @@ -105,7 +102,8 @@
<artifactId>de.metas.fresh.base</artifactId>
<version>${metasfresh.version}</version>
<exclusions>
<!-- TODO: i think we shall remove this dep. from de.metas.fresh.base !!! -->
<!-- TODO: i think we shall remove this dep. from de.metas.fresh.base
!!! -->
<exclusion>
<groupId>de.metas.adempiere.adempiere</groupId>
<artifactId>de.metas.adempiere.adempiere.serverRoot.base</artifactId>
Expand All @@ -125,7 +123,7 @@
<version>${metasfresh.version}</version>
</dependency>

<!-- note that the code is not called by metasfresh-webui-api (currently!)
<!-- note that the code is not called by metasfresh-webui-api (currently!)
but there are model interceptors etc that should be present -->
<dependency>
<groupId>de.metas.vertical.pharma</groupId>
Expand Down Expand Up @@ -161,6 +159,15 @@
<version>${metasfresh.version}</version>
</dependency>

<dependency>
<groupId>de.metas.handlingunits</groupId>
<artifactId>de.metas.handlingunits.base</artifactId>
<version>${metasfresh.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>


<!-- Elasticsearch -->
<dependency>
<groupId>de.metas.elasticsearch</groupId>
Expand Down Expand Up @@ -235,7 +242,7 @@
</dependency>

<!-- Test dependencies -->
<!-- remember, jmockit needs to be before junit in the classpath -->
<!-- remember, jmockit needs to be before junit in the classpath -->
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
Expand All @@ -248,7 +255,8 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<!-- excluded to avoid maven-enforcer-plugin error: Duplicate classes found: org.ow2.asm:asm:jar:5.0.3:test, net.minidev:accessors-smart:jar:1.1:test -->
<!-- excluded to avoid maven-enforcer-plugin error: Duplicate classes
found: org.ow2.asm:asm:jar:5.0.3:test, net.minidev:accessors-smart:jar:1.1:test -->
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
Expand All @@ -268,10 +276,9 @@
<build>
<finalName>metasfresh-webui-api</finalName>
<plugins>
<!--
See http://www.mojohaus.org/versions-maven-plugin/examples/update-properties.html
Note that the propery needs to be declared in the actual child poms, see http://stackoverflow.com/questions/3628471/maven-versions-plugin-not-picking-up-properties-from-parent
-->
<!-- See http://www.mojohaus.org/versions-maven-plugin/examples/update-properties.html
Note that the propery needs to be declared in the actual child poms, see
http://stackoverflow.com/questions/3628471/maven-versions-plugin-not-picking-up-properties-from-parent -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
Expand All @@ -288,7 +295,8 @@
</configuration>
</plugin>

<!-- Add the generic info plus ci build info to the manifests of all jars that we create -->
<!-- Add the generic info plus ci build info to the manifests of all jars
that we create -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -353,8 +361,8 @@
<executable>true</executable>

<!-- this also provides the super-jar to the successive docker build
Note that the ${docker.build.directory} property is set by the prepare-docker profile
that is activated by the presence of the scr/main/docker folder -->
Note that the ${docker.build.directory} property is set by the prepare-docker
profile that is activated by the presence of the scr/main/docker folder -->
<outputDirectory>${docker.build.directory}</outputDirectory>
</configuration>
</execution>
Expand Down
@@ -0,0 +1,182 @@
package de.metas.ui.web.pickingV2.productsToPick;

import static org.adempiere.model.InterfaceWrapperHelper.newInstance;
import static org.adempiere.model.InterfaceWrapperHelper.saveRecord;

import java.time.LocalDate;

import javax.annotation.Nullable;

import org.adempiere.mm.attributes.AttributeId;
import org.adempiere.mm.attributes.api.AttributeConstants;
import org.adempiere.model.InterfaceWrapperHelper;
import org.adempiere.warehouse.LocatorId;
import org.adempiere.warehouse.WarehouseId;
import org.compiere.model.I_C_UOM;
import org.compiere.model.I_M_Attribute;
import org.compiere.model.X_M_Attribute;
import org.compiere.util.TimeUtil;

import de.metas.adempiere.model.I_M_Product;
import de.metas.handlingunits.HuId;
import de.metas.handlingunits.HuPackingInstructionsId;
import de.metas.handlingunits.HuPackingInstructionsVersionId;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.I_M_HU_Attribute;
import de.metas.handlingunits.model.I_M_HU_PI;
import de.metas.handlingunits.model.I_M_HU_PI_Attribute;
import de.metas.handlingunits.model.I_M_HU_PI_Version;
import de.metas.handlingunits.model.I_M_HU_Storage;
import de.metas.handlingunits.model.I_M_Locator;
import de.metas.handlingunits.model.I_M_Warehouse;
import de.metas.handlingunits.model.X_M_HU;
import de.metas.handlingunits.model.X_M_HU_PI_Version;
import de.metas.handlingunits.test.misc.builders.HUPIAttributeBuilder;
import de.metas.product.ProductId;
import de.metas.quantity.Quantity;
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import de.metas.util.NumberUtils;
import lombok.Builder;
import lombok.NonNull;

/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2019 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

final class PickingV2TestHelper
{
public final I_C_UOM uomKg;
public final AttributeId bestBeforeDateAttributeId;
private int huPIAttributeId_VHU_BestBeforeDate;

public PickingV2TestHelper()
{
uomKg = createUOM("Kg");
bestBeforeDateAttributeId = createAttribute(AttributeConstants.ATTR_BestBeforeDate, X_M_Attribute.ATTRIBUTEVALUETYPE_Date);
createVirtualPI();
}

public AttributeId createAttribute(
@NonNull final String code,
@NonNull final String valueType)
{
I_M_Attribute attribute = newInstance(I_M_Attribute.class);
attribute.setValue(code);
attribute.setName(code);
attribute.setAttributeValueType(valueType);
saveRecord(attribute);
return AttributeId.ofRepoId(attribute.getM_Attribute_ID());
}

public I_C_UOM createUOM(final String symbol)
{
I_C_UOM record = newInstance(I_C_UOM.class);
record.setUOMSymbol(symbol);
saveRecord(record);
return record;
}

public ProductId createProduct(final String code)
{
I_M_Product record = newInstance(I_M_Product.class);
record.setValue(code);
record.setName(code);
saveRecord(record);
return ProductId.ofRepoId(record.getM_Product_ID());
}

public WarehouseId createWarehouse()
{
I_M_Warehouse record = newInstance(I_M_Warehouse.class);
saveRecord(record);
return WarehouseId.ofRepoId(record.getM_Warehouse_ID());
}

public LocatorId createLocator(final WarehouseId warehouseId)
{
I_M_Locator record = newInstance(I_M_Locator.class);
record.setM_Warehouse_ID(warehouseId.getRepoId());
saveRecord(record);
return LocatorId.ofRecord(record);
}

@Builder(builderMethodName = "prepareExistingHU", builderClassName = "ExistingHUBuilder")
private HuId createExistingHU(
@NonNull final LocatorId locatorId,
@Nullable final LocalDate bestBeforeDate,
@NonNull final ProductId productId,
@NonNull final Quantity qty)
{
final I_M_HU hu = newInstance(I_M_HU.class);
hu.setM_HU_PI_Version_ID(HuPackingInstructionsVersionId.VIRTUAL.getRepoId());
hu.setHUStatus(X_M_HU.HUSTATUS_Active);
hu.setM_Locator_ID(locatorId.getRepoId());
saveRecord(hu);

final I_M_HU_Attribute huAttribute = newInstance(I_M_HU_Attribute.class);
huAttribute.setM_HU_ID(hu.getM_HU_ID());
huAttribute.setM_HU_PI_Attribute_ID(huPIAttributeId_VHU_BestBeforeDate);
huAttribute.setM_Attribute_ID(bestBeforeDateAttributeId.getRepoId());
huAttribute.setValueDate(TimeUtil.asTimestamp(bestBeforeDate));
saveRecord(huAttribute);

final I_M_HU_Storage huStorage = newInstance(I_M_HU_Storage.class);
huStorage.setM_HU_ID(hu.getM_HU_ID());
huStorage.setM_Product_ID(productId.getRepoId());
huStorage.setQty(qty.toBigDecimal());
huStorage.setC_UOM_ID(qty.getUomId().getRepoId());
saveRecord(huStorage);

return HuId.ofRepoId(hu.getM_HU_ID());
}

public void createVirtualPI()
{
final I_M_HU_PI pi = InterfaceWrapperHelper.newInstance(I_M_HU_PI.class);
pi.setName("VirtualPI");
pi.setM_HU_PI_ID(HuPackingInstructionsId.VIRTUAL.getRepoId());
saveRecord(pi);

final I_M_HU_PI_Version version = InterfaceWrapperHelper.newInstance(I_M_HU_PI_Version.class);
version.setName(pi.getName());
version.setM_HU_PI_ID(pi.getM_HU_PI_ID());
version.setIsCurrent(true);
version.setHU_UnitType(X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI);
version.setM_HU_PI_Version_ID(HuPackingInstructionsVersionId.VIRTUAL.getRepoId());
saveRecord(version);

final I_M_HU_PI_Attribute huPIAttribute = HUPIAttributeBuilder.newInstance(bestBeforeDateAttributeId)
.setM_HU_PI_Version(HuPackingInstructionsVersionId.VIRTUAL)
.create();
huPIAttributeId_VHU_BestBeforeDate = huPIAttribute.getM_HU_PI_Attribute_ID();
}

public IntegerLookupValue locatorLookupById(final Object idObj)
{
if (idObj == null)
{
return null;
}
final int id = NumberUtils.asIntegerOrNull(idObj);
return IntegerLookupValue.of(id, "locator-" + id);
}

}

0 comments on commit c877bf3

Please sign in to comment.