initial commit
This commit is contained in:
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.base.test;
|
||||
|
||||
import com.axelor.apps.tool.file.CsvTool;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
public class ExportObject {
|
||||
|
||||
public static List<String> fieldAttrs =
|
||||
Arrays.asList("object", "module", "name", "type", "title", "help");
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
private SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
|
||||
|
||||
private List<Map<String, Object>> menuList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
private Map<String, Object> objectMap = new HashMap<String, Object>();
|
||||
|
||||
private List<String[]> fieldDataList = new ArrayList<String[]>();
|
||||
|
||||
private List<String> objectList = new ArrayList<String>();
|
||||
|
||||
private String modulesPath = "/home/axelor/axelor-erp/gradle/axelor-erp/modules";
|
||||
|
||||
private String csvPath = "/home/axelor/Desktop/";
|
||||
|
||||
@Test
|
||||
public void exportObject() {
|
||||
|
||||
File moduleDir = new File(modulesPath);
|
||||
|
||||
if (moduleDir.exists()) {
|
||||
prepareObject(Arrays.asList(moduleDir.listFiles()));
|
||||
} else {
|
||||
log.debug("Module source directory not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareObject(List<File> modules) {
|
||||
|
||||
try {
|
||||
XmlHandler xmlHandler = new XmlHandler();
|
||||
SAXParser parser = saxParserFactory.newSAXParser();
|
||||
|
||||
for (File module : modules) {
|
||||
String modulePath = module.getAbsolutePath();
|
||||
File menuFile = new File(modulePath + "/src/main/resources/views/Menu.xml");
|
||||
|
||||
if (menuFile.exists()) {
|
||||
log.debug("Parsing menu: {}", menuFile.getAbsolutePath());
|
||||
parser.parse(new InputSource(new FileInputStream(menuFile)), xmlHandler);
|
||||
}
|
||||
}
|
||||
updateMenuGraph(xmlHandler, null);
|
||||
Collections.sort(menuList, new MenuComparator());
|
||||
updateObjectMap(modules, parser, xmlHandler);
|
||||
writeCsv();
|
||||
|
||||
} catch (SAXException | IOException | ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Object updateMenuGraph(XmlHandler xmlHandler, String parentName) {
|
||||
|
||||
List<String> keyList = new ArrayList<String>(xmlHandler.menuMap.keySet());
|
||||
List<Map<String, Object>> children = new ArrayList<Map<String, Object>>();
|
||||
|
||||
for (String menuName : keyList) {
|
||||
Map<String, String> menuMap = xmlHandler.menuMap.get(menuName);
|
||||
if (menuMap == null) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> menuGraph = new HashMap<String, Object>();
|
||||
menuGraph.put("priority", menuMap.get("priority"));
|
||||
menuGraph.put("object", menuMap.get("object"));
|
||||
menuGraph.put("name", menuName);
|
||||
String parent = menuMap.get("parent");
|
||||
|
||||
if (parent == null) {
|
||||
xmlHandler.menuMap.remove(menuName);
|
||||
menuGraph.put("children", updateMenuGraph(xmlHandler, menuName));
|
||||
menuList.add(menuGraph);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parent.equals(parentName)) {
|
||||
xmlHandler.menuMap.remove(menuName);
|
||||
menuGraph.put("children", updateMenuGraph(xmlHandler, menuName));
|
||||
children.add(menuGraph);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(children, new MenuComparator());
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void updateObjectMap(List<File> modules, SAXParser parser, XmlHandler xmlHandler)
|
||||
throws SAXException, IOException {
|
||||
|
||||
for (File module : modules) {
|
||||
String modulePath = module.getAbsolutePath();
|
||||
File modelDir = new File(modulePath + "/src/main/resources/domains/");
|
||||
if (!modelDir.exists()) {
|
||||
continue;
|
||||
}
|
||||
log.debug("Module : {}", modelDir.getAbsolutePath());
|
||||
|
||||
for (File objectFile : modelDir.listFiles()) {
|
||||
log.debug("Parsing domain : {}", objectFile.getName());
|
||||
String objectName = objectFile.getName().split("\\.")[0];
|
||||
|
||||
if (xmlHandler.objectList.contains(objectName)) {
|
||||
parser.parse(new InputSource(new FileInputStream(objectFile)), xmlHandler);
|
||||
Map<String, Object> moduleMap = (Map<String, Object>) objectMap.get(objectName);
|
||||
if (moduleMap == null) {
|
||||
moduleMap = new HashMap<String, Object>();
|
||||
}
|
||||
moduleMap.put(module.getName(), xmlHandler.fieldList);
|
||||
objectMap.put(objectName, moduleMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCsv() {
|
||||
try {
|
||||
updateObjectList(menuList);
|
||||
updateFieldList();
|
||||
String[] headers = fieldAttrs.toArray(new String[fieldAttrs.size()]);
|
||||
CsvTool.csvWriter(csvPath, "ExportObj.csv", ';', headers, fieldDataList);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void updateObjectList(List<Map<String, Object>> orderedMenuList) {
|
||||
|
||||
Iterator<Map<String, Object>> menuIterator = orderedMenuList.iterator();
|
||||
while (menuIterator.hasNext()) {
|
||||
Map<String, Object> menu = menuIterator.next();
|
||||
String objectName = (String) menu.get("object");
|
||||
if (objectName != null && !objectList.contains(objectName)) {
|
||||
objectList.add(objectName);
|
||||
}
|
||||
List<Map<String, Object>> childrenMenuList = (List<Map<String, Object>>) menu.get("children");
|
||||
if (!childrenMenuList.isEmpty()) updateObjectList(childrenMenuList);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void updateFieldList() {
|
||||
|
||||
for (String objName : objectList) {
|
||||
String[] objectName = objName.split("\\.");
|
||||
Map<String, Object> moduleMap =
|
||||
(Map<String, Object>) objectMap.get(objectName[objectName.length - 1]);
|
||||
log.debug("Adding object: {}", objectName[objectName.length - 1]);
|
||||
if (moduleMap == null) {
|
||||
log.debug("No domain file found for: {}", objName);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Entry<String, Object> module : moduleMap.entrySet()) {
|
||||
String moduleName = module.getKey();
|
||||
for (Map<String, String> field : (List<Map<String, String>>) module.getValue()) {
|
||||
Iterator<String> fieldAtt = fieldAttrs.iterator();
|
||||
List<String> fieldData = new ArrayList<String>();
|
||||
field.put("object", objName);
|
||||
field.put("module", moduleName);
|
||||
while (fieldAtt.hasNext()) {
|
||||
fieldData.add(field.get(fieldAtt.next()));
|
||||
}
|
||||
fieldDataList.add(fieldData.toArray(new String[fieldData.size()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class XmlHandler extends DefaultHandler {
|
||||
|
||||
public List<String> objectList = new ArrayList<String>();
|
||||
|
||||
public Map<String, Map<String, String>> menuMap = new HashMap<String, Map<String, String>>();
|
||||
|
||||
private Map<String, String> actionMenuMap = new HashMap<String, String>();
|
||||
|
||||
public List<Map<String, String>> fieldList;
|
||||
|
||||
private boolean isObject = false;
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
switch (qName) {
|
||||
case "menuitem":
|
||||
{
|
||||
if (attributes.getValue("top") == null) {
|
||||
handleMenu(attributes);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "action-view":
|
||||
{
|
||||
handleAction(attributes);
|
||||
break;
|
||||
}
|
||||
case "entity":
|
||||
{
|
||||
isObject = true;
|
||||
fieldList = new ArrayList<Map<String, String>>();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (isObject) {
|
||||
Map<String, String> fieldMap = new HashMap<String, String>();
|
||||
fieldMap.put("type", qName);
|
||||
for (String fieldAttr : ExportObject.fieldAttrs) {
|
||||
if (attributes.getValue(fieldAttr) != null) {
|
||||
fieldMap.put(fieldAttr, attributes.getValue(fieldAttr));
|
||||
}
|
||||
}
|
||||
fieldList.add(fieldMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
|
||||
if (qName.equals("entity")) {
|
||||
isObject = false;
|
||||
}
|
||||
super.endElement(uri, localName, qName);
|
||||
}
|
||||
|
||||
public void handleMenu(Attributes attributes) {
|
||||
|
||||
Map<String, String> menuAttr = new HashMap<String, String>();
|
||||
String name = attributes.getValue("name");
|
||||
menuAttr.put("parent", attributes.getValue("parent"));
|
||||
menuAttr.put("priority", attributes.getValue("priority"));
|
||||
if (attributes.getValue("action") != null) {
|
||||
actionMenuMap.put(attributes.getValue("action"), name);
|
||||
}
|
||||
menuMap.put(name, menuAttr);
|
||||
}
|
||||
|
||||
public void handleAction(Attributes attributes) {
|
||||
|
||||
String name = attributes.getValue("name");
|
||||
String model = attributes.getValue("model");
|
||||
|
||||
if (actionMenuMap.containsKey(name) && model != null) {
|
||||
Map<String, String> menu = menuMap.get(actionMenuMap.get(name));
|
||||
menu.put("object", model);
|
||||
menuMap.put(actionMenuMap.get(name), menu);
|
||||
String objectName[] = model.split("\\.");
|
||||
if (!objectList.contains(objectName[objectName.length - 1]))
|
||||
objectList.add(objectName[objectName.length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MenuComparator implements Comparator<Map<String, Object>> {
|
||||
|
||||
@Override
|
||||
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
||||
|
||||
Integer priority1 =
|
||||
o1.get("priority") != null ? Integer.parseInt(o1.get("priority").toString()) : 0;
|
||||
Integer priority2 =
|
||||
o2.get("priority") != null ? Integer.parseInt(o2.get("priority").toString()) : 0;
|
||||
if (priority1 < priority2) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.base.test;
|
||||
|
||||
import com.axelor.apps.tool.file.CsvTool;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class PrepareCsv {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
@Test
|
||||
public void prepareCsv() {
|
||||
String xmlDir = System.getProperty("xmlDir");
|
||||
String csvDir = System.getProperty("csvDir");
|
||||
List<String> ignoreType = Arrays.asList("one-to-one", "many-to-many", "one-to-many");
|
||||
try {
|
||||
if (xmlDir != null && csvDir != null) {
|
||||
File xDir = new File(xmlDir);
|
||||
File cDir = new File(csvDir);
|
||||
List<String[]> blankData = new ArrayList<String[]>();
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
if (xDir.isDirectory() && cDir.isDirectory()) {
|
||||
for (File xf : xDir.listFiles()) {
|
||||
LOG.info("Processing XML: " + xf.getName());
|
||||
List<String> fieldList = new ArrayList<String>();
|
||||
Document doc = dBuilder.parse(xf);
|
||||
NodeList nList = doc.getElementsByTagName("module");
|
||||
String module = nList.item(0).getAttributes().getNamedItem("name").getNodeValue();
|
||||
nList = doc.getElementsByTagName("entity");
|
||||
if (nList != null) {
|
||||
NodeList fields = nList.item(0).getChildNodes();
|
||||
Integer count = 0;
|
||||
String csvFileName =
|
||||
module
|
||||
+ "_"
|
||||
+ CaseFormat.UPPER_CAMEL.to(
|
||||
CaseFormat.LOWER_CAMEL, xf.getName().replace(".xml", ".csv"));
|
||||
while (count < fields.getLength()) {
|
||||
Node field = fields.item(count);
|
||||
NamedNodeMap attrs = field.getAttributes();
|
||||
String type = field.getNodeName();
|
||||
if (attrs != null
|
||||
&& attrs.getNamedItem("name") != null
|
||||
&& !ignoreType.contains(type)) {
|
||||
String fieldName = attrs.getNamedItem("name").getNodeValue();
|
||||
if (type.equals("many-to-one")) {
|
||||
String[] objName = attrs.getNamedItem("ref").getNodeValue().split("\\.");
|
||||
String refName = objName[objName.length - 1];
|
||||
String nameColumn = getNameColumn(xmlDir + "/" + refName + ".xml");
|
||||
if (nameColumn != null) fieldList.add(fieldName + "." + nameColumn);
|
||||
else {
|
||||
fieldList.add(fieldName);
|
||||
LOG.error(
|
||||
"No name column found for "
|
||||
+ refName
|
||||
+ ", field '"
|
||||
+ attrs.getNamedItem("name").getNodeValue()
|
||||
+ "'");
|
||||
}
|
||||
} else fieldList.add(fieldName);
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
CsvTool.csvWriter(
|
||||
csvDir, csvFileName, ';', StringUtils.join(fieldList, ",").split(","), blankData);
|
||||
LOG.info("CSV file prepared: " + csvFileName);
|
||||
}
|
||||
}
|
||||
|
||||
} else LOG.error("XML and CSV paths must be directory");
|
||||
} else LOG.error("Please input XML and CSV directory path");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String getNameColumn(String fileName)
|
||||
throws SAXException, IOException, ParserConfigurationException {
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
File domainFile = new File(fileName);
|
||||
if (!domainFile.exists()) return null;
|
||||
Document doc = dBuilder.parse(domainFile);
|
||||
NodeList nList = doc.getElementsByTagName("entity");
|
||||
if (nList != null) {
|
||||
NodeList fields = nList.item(0).getChildNodes();
|
||||
Integer count = 0;
|
||||
while (count < fields.getLength()) {
|
||||
NamedNodeMap attrs = fields.item(count).getAttributes();
|
||||
count++;
|
||||
if (attrs != null && attrs.getNamedItem("name") != null) {
|
||||
String name = attrs.getNamedItem("name").getNodeValue();
|
||||
if (name.equals("importId")) return "importId";
|
||||
else if (name.equals("code")) return "code";
|
||||
else if (name.equals("name")) return "name";
|
||||
else continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.base.test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestImportDateTime {
|
||||
@Test
|
||||
public void testDateTimeImport() {
|
||||
LocalDate dt = LocalDate.now();
|
||||
LocalDate dt2 = dt.plusDays(2);
|
||||
|
||||
System.out.println(dt);
|
||||
System.out.println(dt2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.base.test;
|
||||
|
||||
import com.axelor.db.JpaModule;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class TestModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new JpaModule("testUnit", true, true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Axelor Business Solutions
|
||||
*
|
||||
* Copyright (C) 2019 Axelor (<http://axelor.com>).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.axelor.apps.base.test;
|
||||
|
||||
import com.axelor.app.AxelorModule;
|
||||
import com.axelor.apps.base.module.AdminModule;
|
||||
import com.axelor.apps.base.module.BaseModule;
|
||||
import com.axelor.apps.base.service.user.UserService;
|
||||
import com.axelor.apps.base.test.UserServiceTest.MyModule;
|
||||
import com.axelor.apps.message.module.MessageModule;
|
||||
import com.axelor.apps.tool.module.ToolModule;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.axelor.test.GuiceModules;
|
||||
import com.axelor.test.GuiceRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(GuiceRunner.class)
|
||||
@GuiceModules({MyModule.class})
|
||||
public class UserServiceTest {
|
||||
|
||||
static UserService userService;
|
||||
|
||||
public static class MyModule extends AxelorModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Beans.class).asEagerSingleton();
|
||||
install(new ToolModule());
|
||||
install(new MessageModule());
|
||||
install(new AdminModule());
|
||||
install(new BaseModule());
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
userService = Beans.get(UserService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchPasswordPatternUpperLowerDigit() {
|
||||
Assert.assertTrue(userService.matchPasswordPattern("Axelor123"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("123Axelor"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("axelor123A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchPasswordPatternUpperLowerSpecial() {
|
||||
Assert.assertTrue(userService.matchPasswordPattern("Axelor=["));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("]-Axelor"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("axelor\"A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchPasswordPatternLowerSpecialDigit() {
|
||||
Assert.assertTrue(userService.matchPasswordPattern(";axelor12"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("axelor12?"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("axelor123A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchPasswordPatternUpperSpecialDigit() {
|
||||
Assert.assertTrue(userService.matchPasswordPattern("AXELOR12!"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("123!AXELOR"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern(";XELOR123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchPasswordPatternUpperLowerSpecialDigit() {
|
||||
Assert.assertTrue(userService.matchPasswordPattern("Axelor!12"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("123Axe+lor"));
|
||||
Assert.assertTrue(userService.matchPasswordPattern("ax[elor123A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotMatchPasswordPattern() {
|
||||
Assert.assertFalse(userService.matchPasswordPattern("Xlr1!2*"));
|
||||
Assert.assertFalse(userService.matchPasswordPattern("AxelorAxelor"));
|
||||
Assert.assertFalse(userService.matchPasswordPattern("axelor123456"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="testUnit" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
|
||||
<properties>
|
||||
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
||||
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/axelor-erp" />
|
||||
|
||||
<property name="javax.persistence.jdbc.user" value="axelor" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
|
||||
<!--
|
||||
value="create" to build a new database on each run;
|
||||
value="update" to modify an existing database;
|
||||
value="create-drop" means the same as "create" but also drops tables when Hibernate closes;
|
||||
value="validate" makes no changes to the database
|
||||
-->
|
||||
<property name="hibernate.hbm2ddl.auto" value="none" />
|
||||
|
||||
<!--
|
||||
<property name="hibernate.show_sql" value="true"/>
|
||||
-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@@ -0,0 +1 @@
|
||||
user.password.pattern = (((?=.*[a-z])(?=.*[A-Z])(?=.*\\d))|((?=.*[a-z])(?=.*[A-Z])(?=.*\\W))|((?=.*[a-z])(?=.*\\d)(?=.*\\W))|((?=.*[A-Z])(?=.*\\d)(?=.*\\W))).{8,}
|
||||
Reference in New Issue
Block a user