historian读取更新
This commit is contained in:
parent
f2ef95802f
commit
d99250ff43
|
|
@ -0,0 +1,335 @@
|
|||
package com.cqu.ge;
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.cqu.ge.TestHelper;
|
||||
import com.ge.ip.hds.historian.API.ArchiveService;
|
||||
import com.ge.ip.hds.historian.API.ArchiveServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.CollectorService;
|
||||
import com.ge.ip.hds.historian.API.CollectorServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.DataStoreService;
|
||||
import com.ge.ip.hds.historian.API.DataStoreServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.TagService;
|
||||
import com.ge.ip.hds.historian.API.TagServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.Archive;
|
||||
import com.ge.ip.hds.historian.DataContracts.ArchiveStatistics;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataStore;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataStoreState;
|
||||
import com.ge.ip.hds.historian.DataContracts.ErrorCode;
|
||||
import com.ge.ip.hds.historian.DataContracts.HistorianOperationException;
|
||||
import com.ge.ip.hds.historian.DataContracts.NativeDataType;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagProperty;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class ArchiveAPITest {
|
||||
|
||||
public ArchiveAPITest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
String cppBringPath="C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer="localhost";
|
||||
|
||||
ConfigurationManager.getInstance()
|
||||
.Initialize(null,historianServer, "administrator", "745518019", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetAllArchives method, of class ArchiveServiceImpl.
|
||||
* @throws HistorianOperationException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllArchives() throws HistorianOperationException {
|
||||
|
||||
System.out.println("GetAllArchives");
|
||||
|
||||
ArchiveService instance = new ArchiveServiceImpl();
|
||||
List<Archive> result = instance.GetAllArchives();
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryArchives() throws Exception {
|
||||
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
ArchiveService instance = new ArchiveServiceImpl();
|
||||
|
||||
/* Test 1 - retrieve any archive */
|
||||
System.out.println("QueryArchives - retrieve any archive");
|
||||
Archive createdArchive = th.createArchive("NewArchive");
|
||||
List<Archive> result = instance.QueryArchives("*", "*", 1000);
|
||||
assertTrue(result.size() >= 1);
|
||||
th.deleteArchive(createdArchive.getName());
|
||||
|
||||
/* Test 2 - retrieve specific pattern */
|
||||
System.out.println("QueryArchives - retrieve specific pattern");
|
||||
createdArchive = th.createArchive("New123");
|
||||
result = instance.QueryArchives("*123*", "U*", 1000);
|
||||
boolean found = false;
|
||||
for (Archive archive2 : result) {
|
||||
if (archive2.getName().contains("123")) {
|
||||
found = true;
|
||||
} else {
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
th.deleteArchive(createdArchive.getName());
|
||||
|
||||
}
|
||||
|
||||
/*@Test
|
||||
public void testQueryArchives_fail() throws HistorianOperationException {
|
||||
|
||||
System.out.println("QueryArchives_fail");
|
||||
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
List<Archive> result = instance.QueryArchives("*Test*", "*", 1000);
|
||||
assertTrue(result.size() == 0);
|
||||
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Test of GetArchive method, of class ArchiveServiceImpl.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testGetArchive() throws Exception {
|
||||
|
||||
System.out.println("GetArchive");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
Archive createdArchive = th.createArchive("NewArchive");
|
||||
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
Archive result = instance.GetArchive(createdArchive.getName(), "User");
|
||||
|
||||
assertEquals(createdArchive.getName(), result.getName());
|
||||
|
||||
th.deleteArchive(createdArchive.getName());
|
||||
|
||||
}
|
||||
|
||||
/*@Test(expected = HistorianOperationException.class)
|
||||
public void testGetArchive_fail() throws HistorianOperationException {
|
||||
|
||||
System.out.println("GetArchive_fail");
|
||||
|
||||
String archiveName = "Test";
|
||||
String datastoreName = "User";
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
Archive result = instance.GetArchive(archiveName, datastoreName);
|
||||
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Test of DeleteArchive method, of class ArchiveServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteArchive() throws Exception {
|
||||
|
||||
System.out.println("DeleteArchive");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
Archive createdArchive = th.createArchive("NewArchive");
|
||||
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
boolean result = instance.DeleteArchive(createdArchive.getName(),createdArchive.getDataStoreName());
|
||||
|
||||
assertTrue(result);
|
||||
|
||||
}
|
||||
|
||||
/*@Test(expected = HistorianOperationException.class)
|
||||
public void testDeleteArchive_fail() throws HistorianOperationException {
|
||||
|
||||
System.out.println("DeleteArchive_fail");
|
||||
|
||||
String archiveName = "Test";
|
||||
String datastoreName = "User";
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
boolean result = instance.DeleteArchive(archiveName, datastoreName);
|
||||
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Test of AddArchive method, of class ArchiveServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testAddArchive() throws Exception {
|
||||
|
||||
System.out.println("AddArchive");
|
||||
|
||||
Archive archive = new Archive();
|
||||
archive.setName("NewArchive");
|
||||
archive.setDataStoreName("User");
|
||||
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
Archive result = instance.AddArchive(archive);
|
||||
|
||||
assertEquals(archive.getName(), result.getName());
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
th.deleteArchive(archive.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of UpdateArchive method, of class ArchiveServiceImpl.
|
||||
*/
|
||||
/*
|
||||
* @Test public void testUpdateArchive() throws Exception { //////////NOT
|
||||
* WORKING///////// System.out.println("UpdateArchive"); //reading input file;
|
||||
* NodeList nList = newDoc.getElementsByTagName("UpdateArchive"); Node nNode =
|
||||
* nList.item(0); Element eElement = (Element) nNode; ////////////////PROBLEM
|
||||
* WITH UPDATE///////////////// //end of reading //creating archive Archive
|
||||
* archive = new Archive();
|
||||
* archive.setName(eElement.getElementsByTagName("ArchiveName").item(0).
|
||||
* getTextContent());
|
||||
* archive.setDataStoreName(eElement.getElementsByTagName("DataStoreName").item(
|
||||
* 0).getTextContent());
|
||||
* archive.setFilename(eElement.getElementsByTagName("FileNameBefore").item(0).
|
||||
* getTextContent()); ArchiveService archiveService = new ArchiveServiceImpl();
|
||||
* archive = archiveService.AddArchive(archive); String archiveName =
|
||||
* archive.getName(); String dataStoreName = archive.getDataStoreName(); //end
|
||||
* of creating archive ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
* Archive archive2 = instance.GetArchive("SathuArchive34","User"); //Archive
|
||||
* archiveproperty = instance.GetArchive(archiveName,dataStoreName);
|
||||
* archive2.setFilename(eElement.getElementsByTagName("FileNameAfter").item(0).
|
||||
* getTextContent()); String updatedname =
|
||||
* eElement.getElementsByTagName("FileNameAfter").item(0).getTextContent();
|
||||
* Archive result = instance.UpdateArchive(archive2); //Archive expResult =
|
||||
* archive; //instance.DeleteArchive(archiveName, dataStoreName);
|
||||
* //datastoreService.DeleteDataStore(dataStoreName);
|
||||
* //assertEquals(archive,result); // TODO review the generated test code and
|
||||
* remove the default call to fail. //fail("The test case is a prototype."); }
|
||||
*/
|
||||
|
||||
/* get archive statistics */
|
||||
@Test
|
||||
public void testGetArchiveStatistics() throws Exception {
|
||||
|
||||
System.out.println("GetArchiveStatistics");
|
||||
|
||||
ArchiveService instance = new ArchiveServiceImpl();
|
||||
ArchiveStatistics result = instance.GetArchiveStatistics("User");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of BackupArchive method, of class ArchiveServiceImpl.
|
||||
*/
|
||||
/*
|
||||
* @Test public void testBackupArchive() throws Exception {
|
||||
*
|
||||
* /////////////WORKING ONLY WITH SYSTEM ARCHIVE////////////
|
||||
* System.out.println("BackupArchive"); //reading input NodeList nList =
|
||||
* newDoc.getElementsByTagName("BackupArchive"); Node nNode = nList.item(0);
|
||||
* Element eElement = (Element) nNode; //end of reading //creating archive
|
||||
* ArchiveService instance = new ArchiveServiceImpl(); Archive archive = new
|
||||
* Archive();
|
||||
* archive.setName(eElement.getElementsByTagName("ArchiveName").item(0).
|
||||
* getTextContent());
|
||||
* archive.setDataStoreName(eElement.getElementsByTagName("DataStoreName").item(
|
||||
* 0).getTextContent()); archive = instance.AddArchive(archive); String
|
||||
* archiveName = archive.getName(); String backupFileName =
|
||||
* eElement.getElementsByTagName("BackupFileName").item(0).getTextContent() ;
|
||||
* String dataStoreName = archive.getDataStoreName(); boolean zipArchive =
|
||||
* false; boolean expResult = true; boolean result =
|
||||
* instance.BackupArchive(archiveName, backupFileName, dataStoreName,
|
||||
* zipArchive); assertEquals(expResult, result); // TODO review the generated
|
||||
* test code and remove the default call to fail.
|
||||
* //fail("The test case is a prototype."); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of RestoreArchive method, of class ArchiveServiceImpl.
|
||||
*/
|
||||
/*
|
||||
* @Test public void testRestoreArchive() throws Exception { ////////////////NOT
|
||||
* WORKING//////////////// System.out.println("RestoreArchive"); //reading input
|
||||
* NodeList nList = newDoc.getElementsByTagName("RestoreArchive"); Node nNode =
|
||||
* nList.item(0); Element eElement = (Element) nNode; //end of reading
|
||||
* //creating archive ArchiveService instance = new ArchiveServiceImpl();
|
||||
* Archive archive = new Archive();
|
||||
* archive.setName(eElement.getElementsByTagName("ArchiveName").item(0).
|
||||
* getTextContent());
|
||||
* archive.setDataStoreName(eElement.getElementsByTagName("DataStoreName").item(
|
||||
* 0).getTextContent()); archive = instance.AddArchive(archive); String
|
||||
* archiveName = archive.getName(); String datastoreName =
|
||||
* archive.getDataStoreName(); String backupFileName =
|
||||
* eElement.getElementsByTagName("BackupFileName").item(0).getTextContent();
|
||||
* ///////////////PROBLEM WITH BACKUP ARCHIVE////////////
|
||||
* instance.BackupArchive(archiveName, backupFileName, datastoreName, false);
|
||||
* //here filename is backup file name //deleting archive
|
||||
* instance.DeleteArchive(archiveName, datastoreName); //restoring from backup
|
||||
* String fileName = backupFileName; Archive result =
|
||||
* instance.RestoreArchive(archiveName, fileName, datastoreName);
|
||||
* assertEquals(result.getName(),archiveName); // TODO review the generated test
|
||||
* code and remove the default call to fail.
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of CloseCurrentArchive method, of class ArchiveServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testCloseCurrentArchive() throws Exception {
|
||||
|
||||
System.out.println("CloseCurrentArchive");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
Archive createdArchive = th.createArchive("CurrentArchive");
|
||||
createdArchive.setIsCurrent(true);
|
||||
|
||||
ArchiveServiceImpl instance = new ArchiveServiceImpl();
|
||||
boolean result = instance.CloseCurrentArchive(createdArchive.getDataStoreName());
|
||||
|
||||
assertTrue(result);
|
||||
th.deleteArchive(createdArchive.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
package com.cqu.ge;
|
||||
|
||||
import com.ge.ip.hds.historian.API.CollectorService;
|
||||
import com.ge.ip.hds.historian.API.CollectorServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorPropertyBase;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
//mvn install:install-file -DgroupId=com.cqu -DartifactId=ge -Dversion=1.0.0 -Dpackaging=jar -Dfile=E:\software\RepMaven\com\cqu\ge\HistorianServiceAPI.jar
|
||||
public class Collector {
|
||||
|
||||
public Collector() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of QueryCollector method, of class CollectorServiceImpl
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testQueryCollector() throws Exception {
|
||||
|
||||
System.out.println("QueryCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
|
||||
List<CollectorPropertyBase> result = instance.QueryCollector("*New*", 1000);
|
||||
|
||||
boolean found = false;
|
||||
for (CollectorPropertyBase collector1 : result) {
|
||||
if (collector1.getName().contains("New"))
|
||||
found = true;
|
||||
|
||||
else
|
||||
found = false;
|
||||
|
||||
}
|
||||
instance.DeleteCollector(cp.getName(), true);
|
||||
assertTrue(found);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetCollector() throws Exception {
|
||||
|
||||
System.out.println("GetCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
|
||||
CollectorProperty result = instance.GetCollector(cp.getName());
|
||||
instance.DeleteCollector(cp.getName(), true);
|
||||
|
||||
assertEquals(cp.getName(), result.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of AddCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testAddCollector() throws Exception {
|
||||
|
||||
System.out.println("AddCollector");
|
||||
|
||||
CollectorProperty collectorProperty = new CollectorProperty();
|
||||
collectorProperty.setName("NewCollector");
|
||||
String collectorName = collectorProperty.getName();
|
||||
|
||||
CollectorServiceImpl instance = new CollectorServiceImpl();
|
||||
CollectorProperty result = instance.AddCollector(collectorProperty);
|
||||
|
||||
instance.DeleteCollector(collectorName, true);
|
||||
assertEquals(collectorName, result.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of DeleteCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteCollector() throws Exception {
|
||||
|
||||
System.out.println("DeleteCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
|
||||
boolean result = instance.DeleteCollector(cp.getName(), true);
|
||||
assertTrue(result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of UpdateCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateCollector() throws Exception {
|
||||
|
||||
System.out.println("UpdateCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
// CollectorProperty cp = th.createCollector("NewCollector");
|
||||
|
||||
|
||||
// String collectorName = cp.getName();
|
||||
String collectorName = "NewCollector";
|
||||
|
||||
CollectorServiceImpl instance = new CollectorServiceImpl();
|
||||
|
||||
CollectorProperty cp = instance.GetCollector(collectorName);
|
||||
cp.setComment("test comment");
|
||||
|
||||
CollectorProperty result = instance.UpdateCollector(collectorName, cp);
|
||||
assertEquals(cp.getComment(), result.getComment());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
package com.cqu.ge;
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.CollectorService;
|
||||
import com.ge.ip.hds.historian.API.CollectorServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorPropertyBase;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class CollectorServiceImplTest {
|
||||
|
||||
public CollectorServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置类,设置HistorianWebServiceCppBridge.dll的位置
|
||||
* historianServer,设置位置,集群模式还是单机模式,和当时安装时候的配置有关
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of QueryCollector method, of class CollectorServiceImpl
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testQueryCollector() throws Exception {
|
||||
|
||||
System.out.println("QueryCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
|
||||
List<CollectorPropertyBase> result = instance.QueryCollector("*New*", 1000);
|
||||
|
||||
boolean found = false;
|
||||
for (CollectorPropertyBase collector1 : result) {
|
||||
if (collector1.getName().contains("New"))
|
||||
found = true;
|
||||
|
||||
else
|
||||
found = false;
|
||||
|
||||
}
|
||||
// instance.DeleteCollector(cp.getName(), true);
|
||||
assertTrue(found);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetCollector() throws Exception {
|
||||
|
||||
System.out.println("GetCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
|
||||
CollectorProperty result = instance.GetCollector(cp.getName());
|
||||
instance.DeleteCollector(cp.getName(), true);
|
||||
|
||||
assertEquals(cp.getName(), result.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of AddCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testAddCollector() throws Exception {
|
||||
|
||||
System.out.println("AddCollector");
|
||||
|
||||
CollectorProperty collectorProperty = new CollectorProperty();
|
||||
collectorProperty.setName("NewCollector");
|
||||
String collectorName = collectorProperty.getName();
|
||||
|
||||
CollectorServiceImpl instance = new CollectorServiceImpl();
|
||||
CollectorProperty result = instance.AddCollector(collectorProperty);
|
||||
|
||||
instance.DeleteCollector(collectorName, true);
|
||||
assertEquals(collectorName, result.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of DeleteCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteCollector() throws Exception {
|
||||
|
||||
System.out.println("DeleteCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
|
||||
boolean result = instance.DeleteCollector(cp.getName(), true);
|
||||
assertTrue(result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of UpdateCollector method, of class CollectorServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateCollector() throws Exception {
|
||||
|
||||
System.out.println("UpdateCollector");
|
||||
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
|
||||
String collectorName = cp.getName();
|
||||
|
||||
CollectorServiceImpl instance = new CollectorServiceImpl();
|
||||
cp.setComment("test comment");
|
||||
|
||||
CollectorProperty result = instance.UpdateCollector(collectorName, cp);
|
||||
assertEquals(cp.getComment(), result.getComment());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package com.cqu.ge;/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.CollectorService;
|
||||
import com.ge.ip.hds.historian.API.CollectorServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.CollectorStatisticsService;
|
||||
import com.ge.ip.hds.historian.API.CollectorStatisticsServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorStatistics;
|
||||
import com.ge.ip.hds.historian.DataContracts.HistorianOperationException;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
public class CollectorStatisticsServiceImplTest {
|
||||
|
||||
public CollectorStatisticsServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test of GetStatistics method, of class CollectorStatisticsServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetStatistics() throws Exception {
|
||||
|
||||
System.out.println("GetStatistics");
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
String collectorName = cp.getName();
|
||||
|
||||
CollectorStatistics collectorStatistics = th.createCollectorStats(1000, 5000);
|
||||
|
||||
CollectorStatisticsService instance = new CollectorStatisticsServiceImpl();
|
||||
instance.SetStatistics(collectorName, collectorStatistics);
|
||||
CollectorStatistics result = instance.GetStatistics(collectorName);
|
||||
|
||||
th.deleteCollector(collectorName);
|
||||
assertEquals(collectorStatistics.getAverageEventRate(),result.getAverageEventRate(),0.0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of SetStatistics method, of class CollectorStatisticsServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testSetStatistics() throws Exception {
|
||||
|
||||
System.out.println("SetStatistics");
|
||||
TestHelper th = new TestHelper();
|
||||
CollectorProperty cp = th.createCollector("NewCollector");
|
||||
String collectorName = cp.getName();
|
||||
|
||||
CollectorStatistics collectorStatistics = th.createCollectorStats(4000, 6000);
|
||||
|
||||
CollectorStatisticsService instance = new CollectorStatisticsServiceImpl();
|
||||
boolean result = instance.SetStatistics(collectorName, collectorStatistics);
|
||||
|
||||
|
||||
th.deleteCollector(collectorName);
|
||||
assertTrue(result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package com.cqu.ge;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.DHSServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.DHSServiceInfo;
|
||||
import com.ge.ip.hds.historian.DataContracts.DHSServiceType;
|
||||
import com.ge.ip.hds.historian.DataContracts.HistorianOperationException;
|
||||
|
||||
|
||||
public class DHSServiceImplTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
String cppBringPath="C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer="localhost";
|
||||
|
||||
ConfigurationManager.getInstance()
|
||||
.Initialize(cppBringPath,historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDHSServices() throws HistorianOperationException {
|
||||
|
||||
System.out.println("testGetDHSServices");
|
||||
|
||||
String dHSServiceMask = "Config*";
|
||||
boolean withReasons = false;
|
||||
|
||||
DHSServiceImpl instance = new DHSServiceImpl();
|
||||
List<DHSServiceInfo> result = instance.GetDHSServices(dHSServiceMask, withReasons);
|
||||
|
||||
if(result.size()!= 0)
|
||||
for(DHSServiceInfo item: result)
|
||||
assertTrue(item.getLocalName().contains("Config"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDHSGetService() throws HistorianOperationException {
|
||||
|
||||
System.out.println("testGetDHSService");
|
||||
|
||||
DHSServiceImpl instance = new DHSServiceImpl();
|
||||
DHSServiceInfo dhsserviceinfo = instance.GetDHSService("ConfigManager_SoumikM2");
|
||||
|
||||
assertEquals("ConfigManager_SoumikM2", dhsserviceinfo.getLocalName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDHSServiceNode() throws HistorianOperationException {
|
||||
|
||||
System.out.println("testAddDHSServiceNode");
|
||||
|
||||
String nodeName= "10.181.212.219";
|
||||
|
||||
DHSServiceImpl instance = new DHSServiceImpl();
|
||||
DHSServiceInfo dhsserviceinfo = instance.AddDHSServiceNode(nodeName,null,false);
|
||||
|
||||
assertEquals(DHSServiceType.DataArchiver, dhsserviceinfo.getDHSServiceType());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteDHSServiceNode() throws HistorianOperationException {
|
||||
|
||||
System.out.println("testDeleteDHSServiceNode");
|
||||
|
||||
DHSServiceImpl instance = new DHSServiceImpl();
|
||||
boolean result = instance.DeleteDHSServiceNode("10.181.212.219",null);
|
||||
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,495 @@
|
|||
package com.cqu.ge;
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.helper.JsonBuilder;
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.DataService;
|
||||
import com.ge.ip.hds.historian.API.DataServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.DataStoreService;
|
||||
import com.ge.ip.hds.historian.API.DataStoreServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.TagService;
|
||||
import com.ge.ip.hds.historian.API.TagServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.CalculationModeType;
|
||||
import com.ge.ip.hds.historian.DataContracts.ConditionCollectionComparisonType;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataCollectionType;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataSample;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataStore;
|
||||
import com.ge.ip.hds.historian.DataContracts.NativeDataType;
|
||||
import com.ge.ip.hds.historian.DataContracts.QualityStatus;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagPropertyBase;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagSamples;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagWithData;
|
||||
import com.ge.ip.hds.historian.DataContracts.TimeResolutionType;
|
||||
import com.ge.ip.hds.historian.DataContracts.TimeStampDeterminedByType;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
public class DataServiceImplTest {
|
||||
|
||||
public DataServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置类,设置HistorianWebServiceCppBridge.dll的位置
|
||||
* historianServer,设置位置,集群模式还是单机模式,和当时安装时候的配置有关
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
// TODO add test methods here.
|
||||
// The methods must be annotated with annotation @Test. For example:
|
||||
//
|
||||
/**
|
||||
* Test of GetCurrentData method, of class DataServiceImpl.
|
||||
*/
|
||||
/**
|
||||
* 测试获取当前数据
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testGetCurrentData_self() throws Exception {
|
||||
|
||||
System.out.println("GetCurrentData");
|
||||
TestHelper th = new TestHelper();
|
||||
|
||||
TagProperty tagCreated = th.createTag("TagForSample1", "Float");
|
||||
String tagName1 = tagCreated.getName();
|
||||
|
||||
tagCreated = th.createTag("TagForSample2", "Float");
|
||||
String tagName2 = tagCreated.getName();
|
||||
|
||||
// String tagName1 = "AirInletDP";
|
||||
// String tagName2 = "AirInletDP_2";
|
||||
|
||||
|
||||
DataService dataService = new DataServiceImpl() {
|
||||
};
|
||||
DataSample dataSample = th.createDataSample("UTC", "100", QualityStatus.Uncertain);
|
||||
|
||||
dataService.CreateTagSample(tagName1, new ArrayList<DataSample>(Arrays.asList(dataSample)));
|
||||
dataService.CreateTagSample(tagName2, new ArrayList<DataSample>(Arrays.asList(dataSample)));
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName1);
|
||||
tagNames.add(tagName2);
|
||||
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
List<TagSamples> result = instance.GetCurrentData(tagNames);
|
||||
|
||||
th.deleteTag(tagName1);
|
||||
th.deleteTag(tagName2);
|
||||
|
||||
assertEquals(tagName1, result.get(0).getTagName());
|
||||
assertEquals(tagName2, result.get(1).getTagName());
|
||||
|
||||
if (result.get(0).getTagName().equals(tagName1) && result.get(1).getTagName().equals(tagName2)) {
|
||||
|
||||
DataSample[] datasamples1 = result.get(0).getSamples();
|
||||
DataSample[] datasamples2 = result.get(1).getSamples();
|
||||
System.out.println(datasamples1);
|
||||
System.out.println(datasamples2);
|
||||
System.out.println("datasamples1[0].getValue():" + datasamples1[0].getValue());
|
||||
System.out.println("datasamples1[0].getValue():" + datasamples2[0].getValue());
|
||||
if (datasamples1[0].getValue().equals(tagName1) && datasamples2[0].getValue().equals(tagName2)) {
|
||||
System.out.println("ll:" + datasamples1[0]);
|
||||
System.out.println("dd:" + datasamples1[1]);
|
||||
assertNull(null);
|
||||
}
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
|
||||
// datastoreService.DeleteDataStore(datastoreName);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentData() throws Exception {
|
||||
|
||||
System.out.println("GetCurrentData");
|
||||
TestHelper th = new TestHelper();
|
||||
|
||||
TagProperty tagCreated = th.createTag("TagForSample1", "Float");
|
||||
String tagName1 = tagCreated.getName();
|
||||
|
||||
tagCreated = th.createTag("TagForSample2", "Float");
|
||||
String tagName2 = tagCreated.getName();
|
||||
|
||||
|
||||
DataService dataService = new DataServiceImpl() {
|
||||
};
|
||||
DataSample dataSample = th.createDataSample("UTC", "100", QualityStatus.Uncertain);
|
||||
|
||||
dataService.CreateTagSample(tagName1, new ArrayList<DataSample>(Arrays.asList(dataSample)));
|
||||
dataService.CreateTagSample(tagName2, new ArrayList<DataSample>(Arrays.asList(dataSample)));
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName1);
|
||||
tagNames.add(tagName2);
|
||||
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
List<TagSamples> result = instance.GetCurrentData(tagNames);
|
||||
|
||||
th.deleteTag(tagName1);
|
||||
th.deleteTag(tagName2);
|
||||
|
||||
assertEquals(tagName1, result.get(0).getTagName());
|
||||
assertEquals(tagName2, result.get(1).getTagName());
|
||||
|
||||
// if (result.get(0).getTagName().equals(tagName1) && result.get(1).getTagName().equals(tagName2)) {
|
||||
// DataSample[] datasamples1 = result.get(0).getSamples();
|
||||
// DataSample[] datasamples2 = result.get(1).getSamples();
|
||||
// if (datasamples1[0].getValue().equals(tagName1) && datasamples2[0].getValue().equals(tagName2)) {
|
||||
// assertNull(null);
|
||||
// }
|
||||
// } else {
|
||||
// fail();
|
||||
// }
|
||||
|
||||
// datastoreService.DeleteDataStore(datastoreName);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetRawDataByTime method, of class DataServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRawDataByTime() throws Exception {
|
||||
|
||||
System.out.println("GetRawDataByTime");
|
||||
TestHelper th = new TestHelper();
|
||||
|
||||
|
||||
// TagProperty tagCreated = th.createTag("NewTag", "Float");
|
||||
// String tagName = tagCreated.getName();
|
||||
|
||||
String tagName = "NewTag";
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName);
|
||||
|
||||
DataService dataService = new DataServiceImpl() {
|
||||
};
|
||||
DataSample dataSample = th.createDataSample("UTC", "72",QualityStatus.Uncertain);
|
||||
|
||||
dataService.CreateTagSample(tagName, new ArrayList<DataSample>(Arrays.asList(dataSample)));
|
||||
|
||||
|
||||
Date cur1 = new Date();
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
cal1.setTime(cur1);
|
||||
cal1.add(Calendar.YEAR, -1);
|
||||
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
cal2.setTime(cur1);
|
||||
cal2.add(Calendar.SECOND, 1);
|
||||
|
||||
Date startTime = cal1.getTime();
|
||||
Date endTime = cal2.getTime();
|
||||
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
List<TagSamples> result = instance.GetRawDataByTime(tagNames, startTime, endTime);
|
||||
|
||||
// th.deleteTag(tagName);
|
||||
|
||||
for (TagSamples tagSamples : result) {
|
||||
System.out.println("tagName:" + tagSamples.getTagName());
|
||||
DataSample[] samples = tagSamples.getSamples();
|
||||
System.out.println(samples.length);
|
||||
for (DataSample sample : samples) {
|
||||
System.out.println("tag_value:" + sample.getValue());
|
||||
}
|
||||
|
||||
// assertEquals(tagName, tagSamples.getTagName());
|
||||
// if (tagSamples.getTagName().equals(tagName)) {
|
||||
// int length = tagSamples.getSamples().length;
|
||||
// if (length == 0) {
|
||||
// assertNull(null);
|
||||
// break;
|
||||
// }
|
||||
// DataSample[] datasample = new DataSample[1];
|
||||
// datasample = tagSamples.getSamples();
|
||||
// assertEquals(datasample[0].getTimeStamp(), dataSample.getTimeStamp());
|
||||
// assertEquals(datasample[0].getValue(), 72);
|
||||
// } else {
|
||||
// fail();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetRawDataByNumber method, of class DataServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRawDataByNumber() throws Exception {
|
||||
|
||||
System.out.println("GetRawDataByNumber");
|
||||
TestHelper th = new TestHelper();
|
||||
|
||||
|
||||
TagProperty tagCreated = th.createTag("NewTag", "Float");
|
||||
String tagName = tagCreated.getName();
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName);
|
||||
|
||||
DataService dataService = new DataServiceImpl() {
|
||||
};
|
||||
DataSample dataSample = th.createDataSample("UTC", "72", QualityStatus.Uncertain);
|
||||
|
||||
dataService.CreateTagSample(tagName, new ArrayList<DataSample>(Arrays.asList(dataSample)));
|
||||
|
||||
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
cal1.setTime(dataSample.getTimeStamp());
|
||||
int startTimeOffset = Integer
|
||||
.parseInt("-1");
|
||||
cal1.add(Calendar.SECOND, -1);
|
||||
|
||||
Date startTime = cal1.getTime();
|
||||
int count = 2;
|
||||
boolean backwardTimeOrder = false;
|
||||
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
|
||||
List<TagSamples> result = instance.GetRawDataByNumber(tagNames, startTime, count, backwardTimeOrder);
|
||||
|
||||
th.deleteTag(tagName);
|
||||
for (TagSamples tagSamples : result) {
|
||||
assertEquals(tagName, tagSamples.getTagName());
|
||||
/*if (tagSamples.getTagName().equals(tagName)) {
|
||||
DataSample[] datasample = new DataSample[1];
|
||||
int length = tagSamples.getSamples().length;
|
||||
if (length == 0) {
|
||||
assertNull(null);
|
||||
break;
|
||||
}
|
||||
datasample = tagSamples.getSamples();
|
||||
assertEquals(datasample[0].getTimeStamp(), d);
|
||||
assertEquals(datasample[0].getValue(), value);
|
||||
} else {
|
||||
fail();
|
||||
}*/
|
||||
}
|
||||
|
||||
// assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetInterpolatedData method, of class DataServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetInterpolatedData() throws Exception {
|
||||
System.out.println("GetInterpolatedData");
|
||||
TestHelper th = new TestHelper();
|
||||
|
||||
TagProperty tagCreated = th.createTag("TagForSample1", "Float");
|
||||
String tagName1 = tagCreated.getName();
|
||||
|
||||
tagCreated = th.createTag("TagForSample2", "Float");
|
||||
String tagName2 = tagCreated.getName();
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName1);
|
||||
tagNames.add(tagName2);
|
||||
|
||||
DataService dataService = new DataServiceImpl() {
|
||||
};
|
||||
DataSample dataSample1 = th.createDataSample("UTC", "10", QualityStatus.Good);
|
||||
DataSample dataSample2 = th.createDataSample("UTC", "12", QualityStatus.Good);
|
||||
|
||||
dataService.CreateTagSample(tagName1, new ArrayList<DataSample>(Arrays.asList(dataSample1)));
|
||||
dataService.CreateTagSample(tagName2, new ArrayList<DataSample>(Arrays.asList(dataSample2)));
|
||||
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
int startTimeOffset = Integer
|
||||
.parseInt("10");
|
||||
cal2.add(Calendar.SECOND, startTimeOffset);
|
||||
Date startTime = cal2.getTime();
|
||||
|
||||
Calendar cal3 = Calendar.getInstance();
|
||||
int endTimeOffset = Integer.parseInt("10");
|
||||
cal3.add(Calendar.SECOND, endTimeOffset);
|
||||
Date endTime = cal3.getTime();
|
||||
|
||||
long intervalMs = Long.parseLong("1000");
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
|
||||
List<TagSamples> result = instance.GetInterpolatedData(tagNames, startTime, endTime, intervalMs);
|
||||
th.deleteTag(tagName1);
|
||||
th.deleteTag(tagName2);
|
||||
|
||||
assertEquals(tagName1, result.get(0).getTagName());
|
||||
assertEquals(tagName2, result.get(1).getTagName());
|
||||
|
||||
// assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of CreateTagSample method, of class DataServiceImpl.
|
||||
* todo 测试获取当前值通过
|
||||
*/
|
||||
@Test
|
||||
public void testCreateTagSample() throws Exception {
|
||||
|
||||
System.out.println("CreateTagSample");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating tag1
|
||||
// TagProperty _tagCreated = testhelper.createTag("NewTag", "Float");
|
||||
|
||||
// String tagName = _tagCreated.getName();
|
||||
|
||||
// end of creating tag1
|
||||
|
||||
DataService dataService = new DataServiceImpl();
|
||||
List<DataSample> dataSamples = null;
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
String tagName = "NewTag";
|
||||
|
||||
ArrayList<DataSample> list = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
DataSample dataSample = testhelper.createDataSample("UTC", "20" + i, QualityStatus.Bad);
|
||||
Thread.sleep(1000);
|
||||
list.add(dataSample);
|
||||
|
||||
}
|
||||
|
||||
dataService.CreateTagSample(tagName, list);
|
||||
|
||||
// datasample created
|
||||
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
|
||||
tagNames.add(tagName);
|
||||
|
||||
List<TagSamples> lis = instance.GetCurrentData(tagNames);
|
||||
DataSample[] sample = lis.get(0).getSamples();
|
||||
System.out.println("tag_value:" + sample[0].getValue());
|
||||
System.out.println("tag_Quality:" + sample[0].getQuality());
|
||||
|
||||
/**
|
||||
* CreateTagSample
|
||||
* tag_value:10
|
||||
* tag_Quality:Bad
|
||||
*/
|
||||
|
||||
// testhelper.deleteTag(tagName);
|
||||
// assertEquals(sample[0].getValue(), dataSample.getValue());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of CreateTagsSample method, of class DataServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testCreateTagsSample() throws Exception {
|
||||
|
||||
System.out.println("CreateTagsSample");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating first tag
|
||||
TagProperty tagCreated = testhelper.createTag("tag1", "Float");
|
||||
String tagName1 = tagCreated.getName();
|
||||
|
||||
// creating 2nd tag
|
||||
tagCreated = testhelper.createTag("tag2", "Float");
|
||||
String tagName2 = tagCreated.getName();
|
||||
|
||||
|
||||
// creating tagsample
|
||||
DataService dataService = new DataServiceImpl();
|
||||
DataSample dataSample = testhelper.createDataSample("UTC", "8", QualityStatus.Good);
|
||||
// datasample created
|
||||
|
||||
DataSample[] datasamples = new DataSample[1];
|
||||
datasamples[0] = dataSample;
|
||||
|
||||
TagWithData tagwithData = testhelper.createTagWithData(datasamples, NativeDataType.Float, tagName1);
|
||||
TagWithData tagwithData2 = testhelper.createTagWithData(datasamples, NativeDataType.Float, tagName2);
|
||||
|
||||
List<TagWithData> tagsDataSample = new ArrayList<TagWithData>();
|
||||
tagsDataSample.add(tagwithData);
|
||||
tagsDataSample.add(tagwithData2);
|
||||
|
||||
DataServiceImpl instance = new DataServiceImpl();
|
||||
instance.CreateTagsSample(tagsDataSample);
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName1);
|
||||
tagNames.add(tagName2);
|
||||
|
||||
List<TagSamples> lis = instance.GetCurrentData(tagNames);
|
||||
DataSample[] sample = lis.get(0).getSamples();
|
||||
testhelper.deleteTag(tagName1);
|
||||
testhelper.deleteTag(tagName2);
|
||||
|
||||
|
||||
assertEquals(sample[0].getValue(), dataSample.getValue());
|
||||
|
||||
DataSample[] sample2 = lis.get(1).getSamples();
|
||||
assertEquals(sample2[0].getValue(), dataSample.getValue());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
package com.cqu.ge;
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.DataStoreService;
|
||||
import com.ge.ip.hds.historian.API.DataStoreServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.Archive;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataStore;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class DataStoreServiceImplTest {
|
||||
|
||||
public DataStoreServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
// TODO add test methods here.
|
||||
// The methods must be annotated with annotation @Test. For example:
|
||||
//
|
||||
/**
|
||||
* Test of GetDataStores method, of class DataStoreServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDataStores() throws Exception {
|
||||
|
||||
System.out.println("GetDataStores");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
DataStoreServiceImpl instance = new DataStoreServiceImpl();
|
||||
// creating a datastore
|
||||
DataStore _dataStoreCreated = testhelper.createDataStore("NewDataStore");
|
||||
|
||||
String dataStoreName = _dataStoreCreated.getName();
|
||||
String dataStoreNameMask = "*";
|
||||
|
||||
List<DataStore> result = instance.GetDataStores(dataStoreNameMask);
|
||||
boolean found = false;
|
||||
for (DataStore datastore1 : result) {
|
||||
if (datastore1.getName().equals(dataStoreName)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
instance.DeleteDataStore(dataStoreName);
|
||||
assertTrue(found);
|
||||
|
||||
// assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetDataStore method, of class DataStoreServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDataStore() throws Exception {
|
||||
|
||||
System.out.println("GetDataStore");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating datastore
|
||||
DataStore _datastoreCreated = testhelper.createDataStore("NewDataStore");
|
||||
String dataStoreName = _datastoreCreated.getName();
|
||||
|
||||
DataStoreServiceImpl instance = new DataStoreServiceImpl();
|
||||
DataStore result = instance.GetDataStore(dataStoreName);
|
||||
instance.DeleteDataStore(dataStoreName);
|
||||
assertEquals(_datastoreCreated.getName(), result.getName());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of DeleteDataStore method, of class DataStoreServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteDataStore() throws Exception {
|
||||
System.out.println("DeleteDataStore");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
// creating datastore
|
||||
DataStore _datastoreCreated = testhelper.createDataStore("NewDataStore");
|
||||
String dataStoreName = _datastoreCreated.getName();
|
||||
|
||||
DataStoreServiceImpl instance = new DataStoreServiceImpl();
|
||||
|
||||
boolean result = instance.DeleteDataStore(dataStoreName);
|
||||
assertTrue(result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of AddDataStore method, of class DataStoreServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testAddDataStore() throws Exception {
|
||||
|
||||
System.out.println("AddDataStore");
|
||||
|
||||
DataStore datastore = new DataStore();
|
||||
datastore.setName("NewDataStore");
|
||||
|
||||
String datastoreName = datastore.getName();
|
||||
|
||||
DataStoreServiceImpl instance = new DataStoreServiceImpl();
|
||||
DataStore result = instance.AddDataStore(datastore);
|
||||
DataStore expResult = instance.GetDataStore(datastoreName);
|
||||
|
||||
instance.DeleteDataStore(datastoreName);
|
||||
assertEquals(expResult.getName(), result.getName());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of UpdateDataStore method, of class DataStoreServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateDataStore() throws Exception {
|
||||
|
||||
System.out.println("UpdateDataStore");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating datastore
|
||||
DataStoreService instance = new DataStoreServiceImpl();
|
||||
DataStore dataStore = testhelper.createDataStore("NewDataStore");
|
||||
String dataStoreName = dataStore.getName();
|
||||
|
||||
dataStore.setDescription("updated description");
|
||||
DataStore result = instance.UpdateDataStore(dataStoreName, dataStore);
|
||||
|
||||
assertEquals(dataStore.getDescription(),result.getDescription());
|
||||
instance.DeleteDataStore(dataStoreName);
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of RenameDataStore method, of class DataStoreServiceImpl.
|
||||
*/
|
||||
/*
|
||||
* @Test public void testRenameDataStore() throws Exception {
|
||||
* System.out.println("RenameDataStore"); //reading input ReadClass readclass =
|
||||
* new ReadClass(); Document document = readclass.Read();
|
||||
* document.getDocumentElement().normalize(); NodeList nList =
|
||||
* document.getElementsByTagName("RenameDataStore"); Node nNode = nList.item(0);
|
||||
* Element eElement = (Element) nNode; //creating datastore DataStore
|
||||
* _datastoreCreated = null; DataStore datastore= new DataStore();
|
||||
* datastore.setName(eElement.getElementsByTagName("DataStoreName").item(0).
|
||||
* getTextContent()); DataStoreService datastoreService = new
|
||||
* DataStoreServiceImpl(); _datastoreCreated =
|
||||
* datastoreService.AddDataStore(datastore); //end of creating datastore String
|
||||
* oldName = datastore.getName(); String newName =
|
||||
* eElement.getElementsByTagName("NewDataStoreName").item(0).getTextContent();
|
||||
*
|
||||
* DataStoreServiceImpl instance = new DataStoreServiceImpl(); DataStore result
|
||||
* = instance.RenameDataStore(oldName, newName);
|
||||
* assertEquals(result.getName(),newName); // TODO review the generated test
|
||||
* code and remove the default call to fail.
|
||||
* //fail("The test case is a prototype."); }
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package com.cqu.ge;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.InterfaceDefService;
|
||||
import com.ge.ip.hds.historian.API.InterfaceDefServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.ErrorCode;
|
||||
import com.ge.ip.hds.historian.DataContracts.HistorianOperationException;
|
||||
import com.ge.ip.hds.historian.DataContracts.InterfaceDef;
|
||||
|
||||
public class InterfaceDefServiceImplTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
String cppBringPath="C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer="localhost";
|
||||
|
||||
ConfigurationManager.getInstance()
|
||||
.Initialize(cppBringPath,historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInterfaceDefs() throws HistorianOperationException {
|
||||
|
||||
System.out.println("GetInterfaceDefs");
|
||||
|
||||
InterfaceDefService instance = new InterfaceDefServiceImpl();
|
||||
List<InterfaceDef> result = instance.GetInterfaceDefs("*");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInterfaceDef() throws HistorianOperationException {
|
||||
|
||||
System.out.println("GetInterfaceDef");
|
||||
|
||||
InterfaceDefService instance = new InterfaceDefServiceImpl();
|
||||
|
||||
InterfaceDef newintDef = new InterfaceDef();
|
||||
newintDef.setInterfaceDefName("TestInterface");
|
||||
instance.AddInterfaceDef(newintDef);
|
||||
|
||||
InterfaceDef result = instance.GetInterfaceDef(newintDef.getInterfaceDefName());
|
||||
instance.DeleteInterfaceDef(newintDef.getInterfaceDefName());
|
||||
|
||||
assertEquals(newintDef.getInterfaceDefName(), result.getInterfaceDefName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddInterfaceDef() throws HistorianOperationException {
|
||||
|
||||
System.out.println("AddInterfaceDef");
|
||||
|
||||
//add and delete
|
||||
|
||||
InterfaceDef intDef = new InterfaceDef();
|
||||
intDef.setInterfaceDefName("TestInterface");
|
||||
intDef.setInterfaceType(16);
|
||||
|
||||
InterfaceDefService instance = new InterfaceDefServiceImpl();
|
||||
ErrorCode result = instance.AddInterfaceDef(intDef);
|
||||
|
||||
instance.DeleteInterfaceDef("TestInterface");
|
||||
assertEquals(ErrorCode.Success,result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteInterfaceDef() throws Exception {
|
||||
|
||||
System.out.println("DeleteInterfaceDef");
|
||||
InterfaceDefService instance = new InterfaceDefServiceImpl();
|
||||
|
||||
//add and delete
|
||||
InterfaceDef newintDef = new InterfaceDef();
|
||||
newintDef.setInterfaceDefName("TestInterface");
|
||||
instance.AddInterfaceDef(newintDef);
|
||||
|
||||
boolean result = instance.DeleteInterfaceDef("TestInterface");
|
||||
|
||||
assertTrue(result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateInterfaceDef() throws HistorianOperationException {
|
||||
|
||||
System.out.println("UpdateInterfaceDef");
|
||||
InterfaceDefService instance = new InterfaceDefServiceImpl();
|
||||
|
||||
//add , update and delete
|
||||
InterfaceDef newintDef = new InterfaceDef();
|
||||
newintDef.setInterfaceDefName("TestInterface");
|
||||
instance.AddInterfaceDef(newintDef);
|
||||
|
||||
InterfaceDef intDef = instance.GetInterfaceDef("TestInterface");
|
||||
intDef.setGeneral1Description("testdescription1");
|
||||
ErrorCode result = instance.UpdateInterfaceDef("TestInterface",intDef);
|
||||
|
||||
instance.DeleteInterfaceDef("TestInterface");
|
||||
assertEquals(ErrorCode.Success,result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
package com.cqu.ge;
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.MessageService;
|
||||
import com.ge.ip.hds.historian.API.MessageServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.Message;
|
||||
import com.ge.ip.hds.historian.DataContracts.MessageTopic;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
public class MessageServiceImplTest {
|
||||
|
||||
public MessageServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
// TODO add test methods here.
|
||||
// The methods must be annotated with annotation @Test. For example:
|
||||
//
|
||||
|
||||
/**
|
||||
* Test of QueryMessage method, of class MessageServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testQueryMessage() throws Exception {
|
||||
|
||||
System.out.println("QueryMessage");
|
||||
|
||||
Message message = new Message();
|
||||
message.setText("Message for query");
|
||||
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
Date date = Date.from( dateTime.atZone( ZoneId.systemDefault()).toInstant());
|
||||
|
||||
message.setTime(date);
|
||||
message.setTopic(MessageTopic.General);
|
||||
|
||||
MessageServiceImpl instance = new MessageServiceImpl();
|
||||
instance.AddMessage(message);
|
||||
// message added
|
||||
|
||||
String messageTextMask = "for";
|
||||
int maxNumber = 1000;
|
||||
|
||||
Date start = Date.from(dateTime.minusDays(1).atZone( ZoneId.systemDefault()).toInstant());
|
||||
|
||||
Date end = Date.from( dateTime.atZone( ZoneId.systemDefault()).toInstant());
|
||||
|
||||
MessageTopic topic = MessageTopic.General;
|
||||
|
||||
List<Message> result = instance.QueryMessage(start, end, messageTextMask, topic, maxNumber);
|
||||
boolean found = false;
|
||||
for (Message msg : result) {
|
||||
if (msg.getText().equals(message.getText())) {
|
||||
found = true;
|
||||
break;
|
||||
} else
|
||||
found = false;
|
||||
}
|
||||
assertTrue(found);
|
||||
// assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of AddMessage method, of class MessageServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testAddMessage() throws Exception {
|
||||
|
||||
System.out.println("AddMessage");
|
||||
|
||||
Message message = new Message();
|
||||
message.setText("This is a test message");
|
||||
// Date time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
|
||||
// .parse("2019-09-18 12:23:0");
|
||||
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
Date date = Date.from( dateTime.atZone( ZoneId.systemDefault()).toInstant());
|
||||
|
||||
message.setTime(date);
|
||||
message.setTopic(MessageTopic.valueOf("General"));
|
||||
|
||||
MessageServiceImpl instance = new MessageServiceImpl();
|
||||
|
||||
boolean result = instance.AddMessage(message);
|
||||
assertTrue(result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.cqu.ge;/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.PerformanceCounterServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.ArchiveStatistics;
|
||||
import com.ge.ip.hds.historian.DataContracts.HistorianConfiguration;
|
||||
import com.ge.ip.hds.historian.DataContracts.PerformanceCounters;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
public class PerformanceCounterServiceImplTest {
|
||||
|
||||
public PerformanceCounterServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
// TODO add test methods here.
|
||||
// The methods must be annotated with annotation @Test. For example:
|
||||
//
|
||||
/**
|
||||
* Test of GetPerformanceCounter method, of class PerformanceCounterServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPerformanceCounter() throws Exception {
|
||||
System.out.println("GetPerformanceCounter");
|
||||
|
||||
//creating performance counter
|
||||
PerformanceCounters performanceCounters = new PerformanceCounters();
|
||||
//performanceCounters.setAverageAlarmRate(eElement.getElementsByTagName("AverageAlarmRate").item(0).getTextContent());
|
||||
PerformanceCounterServiceImpl instance = new PerformanceCounterServiceImpl();
|
||||
PerformanceCounters result = instance.GetPerformanceCounter();
|
||||
int maxDataStores = Integer.parseInt("200");
|
||||
HistorianConfiguration hist = result.getHistConfig();
|
||||
assertEquals(hist.getMaxDataStores(),maxDataStores);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
//fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,352 @@
|
|||
package com.cqu.ge;
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.TagService;
|
||||
import com.ge.ip.hds.historian.API.TagServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataCollectionType;
|
||||
import com.ge.ip.hds.historian.DataContracts.NativeDataType;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagPropertyBase;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class TagServiceImplTest {
|
||||
|
||||
public TagServiceImplTest() throws Exception {
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
// TODO add test methods here.
|
||||
// The methods must be annotated with annotation @Test. For example:
|
||||
//
|
||||
/**
|
||||
* Test of BrowseTag method, of class TagServiceImpl.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testBrowseTag() throws Exception {
|
||||
|
||||
System.out.println("BrowseTag");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating a tag
|
||||
TagProperty _tagCreated = testhelper.createTag("TestBrowseTag", "Integer");
|
||||
// end of creating tag
|
||||
|
||||
String tagName = _tagCreated.getName();
|
||||
String tagNameMask = "*Test*";
|
||||
int maxNumber = 100;
|
||||
|
||||
TagServiceImpl instance = new TagServiceImpl();
|
||||
List<TagPropertyBase> result = instance.BrowseTag(tagNameMask, maxNumber);
|
||||
|
||||
boolean found = false; //all tags in result must have the tagmask pattern
|
||||
for (TagPropertyBase tagproperty : result) {
|
||||
if (tagproperty.getName().equals(tagName)) {
|
||||
found = true;
|
||||
break;
|
||||
} else
|
||||
found = false;
|
||||
}
|
||||
instance.DeleteTag(tagName, true);
|
||||
assertTrue(found);
|
||||
|
||||
// assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of QueryTagByFilter method, of class TagServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testQueryTagByFilter() throws Exception {
|
||||
System.out.println("QueryTagByFilter");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating a tag
|
||||
TagProperty tagCreated = testhelper.createTag("dummytag", "Integer");
|
||||
|
||||
|
||||
String tagName = tagCreated.getName();
|
||||
String tagNameMask = tagName;
|
||||
String descriptionMask = "";
|
||||
|
||||
String dataStoreName = "User";
|
||||
String collectorName = "";
|
||||
String customTypeNameMask = "";
|
||||
int maxNumber = 1;
|
||||
|
||||
TagServiceImpl instance = new TagServiceImpl();
|
||||
List<TagPropertyBase> result = instance.QueryTagByFilter(tagNameMask, descriptionMask, dataStoreName,
|
||||
collectorName, customTypeNameMask, maxNumber);
|
||||
testhelper.deleteTag(tagName);
|
||||
|
||||
assertEquals(result.get(0).getName(), tagName);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetTag method, of class TagServiceImpl.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testGetTag() throws Exception {
|
||||
|
||||
System.out.println("GetTag");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
// creating a new tag
|
||||
TagProperty _tagCreated = testhelper.createTag("NewTag", "Integer");
|
||||
String tagName = _tagCreated.getName();
|
||||
|
||||
TagServiceImpl instance = new TagServiceImpl();
|
||||
TagProperty result = instance.GetTag(tagName);
|
||||
instance.DeleteTag(tagName, true);
|
||||
|
||||
assertEquals(tagName, result.getName());
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of AddTag method, of class TagServiceImpl.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAddTag() throws Exception {
|
||||
|
||||
System.out.println("AddTag");
|
||||
|
||||
// creating tag
|
||||
TagProperty tagProperty = new TagProperty();
|
||||
tagProperty.setName("NewTag");
|
||||
tagProperty.setDataType(
|
||||
NativeDataType.valueOf("DoubleInteger"));
|
||||
tagProperty.setId(UUID.randomUUID());
|
||||
tagProperty.setDataStoreName("User");
|
||||
String tagName = tagProperty.getName();
|
||||
|
||||
TagServiceImpl instance = new TagServiceImpl();
|
||||
TagProperty result = instance.AddTag(tagProperty);
|
||||
TagProperty expResult = instance.GetTag(tagName);
|
||||
instance.DeleteTag(tagName, true);
|
||||
assertEquals(expResult.getName(), result.getName());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of RenameTag method, of class TagServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testRenameTag() throws Exception {
|
||||
|
||||
System.out.println("RenameTag");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating a new tag
|
||||
TagService instance = new TagServiceImpl();
|
||||
TagProperty _tagCreated = testhelper.createTag("NewTag", "Integer");
|
||||
_tagCreated.setDescription("description remains unchanged");
|
||||
|
||||
|
||||
String oldName = _tagCreated.getName();
|
||||
String newName = "TagNameChanged";
|
||||
|
||||
boolean trueRename = true;
|
||||
TagProperty result = instance.RenameTag(oldName, newName, trueRename);
|
||||
TagProperty expResult = instance.GetTag(newName);
|
||||
instance.DeleteTag(newName, true);
|
||||
|
||||
assertEquals(expResult.getDescription(), result.getDescription());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of DeleteTag method, of class TagServiceImpl.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteTag() throws Exception {
|
||||
|
||||
System.out.println("DeleteTag");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
TagProperty _tagCreated = testhelper.createTag("NewTag", "Float");
|
||||
|
||||
String tagName = _tagCreated.getName();
|
||||
TagServiceImpl instance = new TagServiceImpl();
|
||||
|
||||
instance.DeleteTag(tagName, true);
|
||||
// permanent and temporary deletion
|
||||
assertFalse(instance.TagExists(tagName));
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of UpdateTag method, of class TagServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateTag() throws Exception {
|
||||
System.out.println("UpdateTag");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating a new tag
|
||||
TagService instance = new TagServiceImpl();
|
||||
TagProperty _tagCreated = testhelper.createTag("NewTag", "Integer");
|
||||
|
||||
String description = " adding description";
|
||||
_tagCreated.setDescription(description);
|
||||
|
||||
String tagName = _tagCreated.getName();
|
||||
|
||||
TagProperty result = instance.UpdateTag(tagName,_tagCreated);
|
||||
testhelper.deleteTag(tagName);
|
||||
assertEquals(description,result.getDescription());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of CopyTag method, of class TagServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testCopyTag() throws Exception {
|
||||
System.out.println("CopyTag");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating a new tag
|
||||
TagService instance = new TagServiceImpl();
|
||||
TagProperty tagCreated = testhelper.createTag("NewTag", "Integer");
|
||||
|
||||
TagProperty expResult = tagCreated;
|
||||
|
||||
String tagName = tagCreated.getName();
|
||||
String copyTagName = "CopiedTag";
|
||||
|
||||
TagProperty result = instance.CopyTag(tagName, copyTagName);
|
||||
|
||||
testhelper.deleteTag(tagName);
|
||||
testhelper.deleteTag(copyTagName);
|
||||
|
||||
assertEquals(result.getDescription(), expResult.getDescription());
|
||||
assertEquals(result.getDataType(), expResult.getDataType());
|
||||
assertEquals(result.getDataStoreName(), expResult.getDataStoreName());
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of GetTagAliasName method, of class TagServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testGetTagAliasName() throws Exception {
|
||||
System.out.println("GetTagAliasName");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
TagService instance = new TagServiceImpl();
|
||||
TagProperty tagCreated = testhelper.createTag("Tag1", "Integer");
|
||||
String tagName = tagCreated.getName();
|
||||
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
tagNames.add(tagName);
|
||||
|
||||
String newName = "NewTagName";
|
||||
instance.RenameTag(tagName, newName, false);
|
||||
|
||||
List<String> result = instance.GetTagAliasName(tagNames);
|
||||
boolean check = false;
|
||||
for (String name : result) {
|
||||
if (name.contains(tagName)) {
|
||||
check = true;
|
||||
break;
|
||||
} else {
|
||||
check = false;
|
||||
}
|
||||
}
|
||||
testhelper.deleteTag(newName);
|
||||
assertTrue(check);
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of TagExists method, of class TagServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testTagExists() throws Exception {
|
||||
|
||||
System.out.println("TagExists");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
// creating a new tag
|
||||
TagService instance = new TagServiceImpl();
|
||||
TagProperty _tagCreated = testhelper.createTag("NewTag", "Integer");
|
||||
|
||||
String tagName = _tagCreated.getName();
|
||||
String dataStoreName = _tagCreated.getDataStoreName();
|
||||
|
||||
boolean result = instance.TagExists(tagName);
|
||||
instance.DeleteTag(tagName, true);
|
||||
|
||||
assertTrue(result);
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
// fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package com.cqu.ge;/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.ge.ip.hds.historian.API.ConfigurationManager;
|
||||
import com.ge.ip.hds.historian.API.TagService;
|
||||
import com.ge.ip.hds.historian.API.TagServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.TagsServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.ItemError;
|
||||
import com.ge.ip.hds.historian.DataContracts.NativeDataType;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagProperty;
|
||||
//import com.ge.ip.hds.historianjavaapitest.ReadClass;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class TagsServiceImplTest {
|
||||
|
||||
public TagsServiceImplTest() throws Exception{
|
||||
// this.newDoc = ob.Read();
|
||||
}
|
||||
|
||||
// ReadClass ob = new ReadClass();
|
||||
Document newDoc;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String cppBringPath = "C:\\Program Files\\Proficy\\Proficy Historian\\x86\\Java API\\HistorianWebServiceCppBridge.dll";
|
||||
String historianServer = "localhost";
|
||||
|
||||
ConfigurationManager.getInstance().Initialize(cppBringPath, historianServer, "", "", 10000, 10000, true, false);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
// TODO add test methods here.
|
||||
// The methods must be annotated with annotation @Test. For example:
|
||||
//
|
||||
|
||||
/**
|
||||
* Test of AddTags method, of class TagsServiceImpl.
|
||||
*/
|
||||
@Test
|
||||
public void testAddTags() throws Exception
|
||||
{
|
||||
|
||||
System.out.println("AddTags");
|
||||
TestHelper testhelper = new TestHelper();
|
||||
|
||||
List<TagProperty> tagsProperty = new ArrayList<TagProperty>();
|
||||
TagProperty tagProperty1 = testhelper.createTag("Tag1", "Integer");
|
||||
String tagName1 = tagProperty1.getName();
|
||||
|
||||
TagProperty tagProperty2 = testhelper.createTag("Tag2", "Float");
|
||||
String tagName2 = tagProperty2.getName();
|
||||
|
||||
tagsProperty.add(0,tagProperty1);
|
||||
tagsProperty.add(1, tagProperty2);
|
||||
|
||||
TagsServiceImpl instance = new TagsServiceImpl();
|
||||
List<ItemError> result = instance.AddTags(tagsProperty);
|
||||
|
||||
TagService tagService = new TagServiceImpl();
|
||||
boolean found1 = tagService.TagExists(tagName1);
|
||||
boolean found2 = tagService.TagExists(tagName2);
|
||||
|
||||
tagService.DeleteTag(tagName1,true);
|
||||
tagService.DeleteTag(tagName2,true);
|
||||
|
||||
assertTrue(found1);
|
||||
assertTrue(found2);
|
||||
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
//fail("The test case is a prototype.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
package com.cqu.ge;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.ge.ip.hds.historian.API.ArchiveService;
|
||||
import com.ge.ip.hds.historian.API.ArchiveServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.CollectorService;
|
||||
import com.ge.ip.hds.historian.API.CollectorServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.DataStoreService;
|
||||
import com.ge.ip.hds.historian.API.DataStoreServiceImpl;
|
||||
import com.ge.ip.hds.historian.API.TagService;
|
||||
import com.ge.ip.hds.historian.API.TagServiceImpl;
|
||||
import com.ge.ip.hds.historian.DataContracts.Archive;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.CollectorStatistics;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataSample;
|
||||
import com.ge.ip.hds.historian.DataContracts.DataStore;
|
||||
import com.ge.ip.hds.historian.DataContracts.HistorianOperationException;
|
||||
import com.ge.ip.hds.historian.DataContracts.NativeDataType;
|
||||
import com.ge.ip.hds.historian.DataContracts.QualityStatus;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagProperty;
|
||||
import com.ge.ip.hds.historian.DataContracts.TagWithData;
|
||||
|
||||
public class TestHelper {
|
||||
|
||||
public Archive createArchive(String archName) throws HistorianOperationException {
|
||||
|
||||
Archive archiveCreated = null;
|
||||
Archive archive = new Archive();
|
||||
archive.setName(archName);
|
||||
archive.setDataStoreName("User");
|
||||
|
||||
ArchiveService archiveService = new ArchiveServiceImpl();
|
||||
archiveCreated = archiveService.AddArchive(archive);
|
||||
|
||||
return archiveCreated;
|
||||
}
|
||||
|
||||
public void deleteArchive(String archName) throws HistorianOperationException {
|
||||
ArchiveService archiveService = new ArchiveServiceImpl();
|
||||
archiveService.DeleteArchive(archName, "User");
|
||||
}
|
||||
|
||||
public CollectorProperty createCollector(String colName) throws HistorianOperationException {
|
||||
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
CollectorProperty collectorProperty = new CollectorProperty();
|
||||
collectorProperty.setName(colName);
|
||||
collectorProperty.setDefaultCollectionType(2);
|
||||
collectorProperty = instance.AddCollector(collectorProperty);
|
||||
|
||||
return collectorProperty;
|
||||
|
||||
}
|
||||
|
||||
public void deleteCollector(String colName) throws HistorianOperationException {
|
||||
CollectorService instance = new CollectorServiceImpl();
|
||||
instance.DeleteCollector(colName, true);
|
||||
}
|
||||
|
||||
public CollectorStatistics createCollectorStats(double avgER, double MaxER) {
|
||||
|
||||
CollectorStatistics collectorStatistics = new CollectorStatistics();
|
||||
collectorStatistics.setAverageEventRate(avgER);
|
||||
collectorStatistics.setMaximumEventRate(MaxER);
|
||||
|
||||
return collectorStatistics;
|
||||
}
|
||||
|
||||
public TagProperty createTag(String tagName, String dType) throws HistorianOperationException {
|
||||
|
||||
TagProperty tagProperty = new TagProperty();
|
||||
|
||||
tagProperty.setName(tagName);
|
||||
tagProperty.setId(UUID.randomUUID());
|
||||
tagProperty.setDataType(
|
||||
NativeDataType.valueOf(dType));
|
||||
|
||||
tagProperty.setDataStoreName("User");
|
||||
|
||||
TagService tagService = new TagServiceImpl();
|
||||
|
||||
//TagServiceImplTest tagService = new TagServiceImplTest();
|
||||
tagProperty=tagService.AddTag(tagProperty);
|
||||
return tagProperty;
|
||||
|
||||
}
|
||||
|
||||
public void deleteTag(String tagName) throws HistorianOperationException {
|
||||
TagService tagService = new TagServiceImpl();
|
||||
tagService.DeleteTag(tagName, true);
|
||||
}
|
||||
|
||||
public DataSample createDataSample(String tz, String value,QualityStatus qs) throws Exception {
|
||||
|
||||
DataSample dataSample = new DataSample();
|
||||
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date dateobj = new Date();
|
||||
|
||||
df.setTimeZone(TimeZone.getTimeZone(tz));
|
||||
df.format(dateobj);
|
||||
|
||||
Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(df.format(dateobj));
|
||||
dataSample.setTimeStamp(d);
|
||||
dataSample.setQuality(qs);
|
||||
|
||||
dataSample.setValue(value);
|
||||
|
||||
return dataSample;
|
||||
}
|
||||
|
||||
public TagWithData createTagWithData(DataSample[] datasamples, NativeDataType dType,String tagName) {
|
||||
TagWithData tagwithData = new TagWithData();
|
||||
tagwithData.setDataSamples(datasamples);
|
||||
tagwithData.setDataType(dType);
|
||||
tagwithData.setTagName(tagName);
|
||||
|
||||
return tagwithData;
|
||||
}
|
||||
|
||||
public DataStore createDataStore(String dsName) throws HistorianOperationException{
|
||||
|
||||
DataStore datastore = new DataStore();
|
||||
datastore.setName(dsName);
|
||||
|
||||
DataStoreService datastoreService = new DataStoreServiceImpl();
|
||||
|
||||
datastore = datastoreService.AddDataStore(datastore);
|
||||
|
||||
return datastore;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
/*
|
||||
添加命令获得token
|
||||
示例:curl -u username:password https://<nodename>/uaa/oauth/token -d grant_type=client_credentials
|
||||
username默认是admin或者是hostname.admin
|
||||
如果grant_type=client_credentials不对可以使用grant_type=password试试
|
||||
curl -u admin:dingjiawen.123 http://localhost:9480/uaa/oauth/token -d grant_type=client_credentials | iconv -f utf-8 -t gbk
|
||||
*/
|
||||
"access_token": "eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vdGVzdC5nZS5jb20ubG9jYWxob3N0OjEwMDUyL3VhYS90b2tlbl9rZXlzIiwia2lkIjoia2V5LWlkLTEiLCJ0eXAiOiJKV1QifQ.eyJqdGkiOiIwZGEyNzk3YzM5ZGU0ZjMwOGIwYTRiODgzNTMyNWU1YyIsInN1YiI6ImFkbWluIiwiYXV0aG9yaXRpZXMiOlsiY2xpZW50cy5yZWFkIiwicGFzc3dvcmQud3JpdGUiLCJjbGllbnRzLnNlY3JldCIsImNsaWVudHMud3JpdGUiLCJ1YWEuYWRtaW4iLCJjbGllbnRzLmFkbWluIiwic2NpbS53cml0ZSIsInNjaW0ucmVhZCJdLCJzY29wZSI6WyJjbGllbnRzLnJlYWQiLCJwYXNzd29yZC53cml0ZSIsImNsaWVudHMuc2VjcmV0IiwiY2xpZW50cy53cml0ZSIsInVhYS5hZG1pbiIsImNsaWVudHMuYWRtaW4iLCJzY2ltLndyaXRlIiwic2NpbS5yZWFkIl0sImNsaWVudF9pZCI6ImFkbWluIiwiY2lkIjoiYWRtaW4iLCJhenAiOiJhZG1pbiIsInJldm9jYWJsZSI6dHJ1ZSwiZ3JhbnRfdHlwZSI6ImNsaWVudF9jcmVkZW50aWFscyIsInJldl9zaWciOiI4MWMyOTU5YyIsImlhdCI6MTY4MzE5MzA3OSwiZXhwIjoxNjgzMjM2Mjc5LCJpc3MiOiJodHRwczovL3Rlc3QuZ2UuY29tLmxvY2FsaG9zdDoxMDA1Mi91YWEvb2F1dGgvdG9rZW4iLCJ6aWQiOiJ1YWEiLCJhdWQiOlsic2NpbSIsInBhc3N3b3JkIiwiY2xpZW50cyIsInVhYSIsImFkbWluIl19.EFhqDhU6pQe18PKMfsLOZXtPRL2XWJqFoi2qcZtrfM6BcHnMoolO6vildyM-XtlsjPpJenxmAavbpAatn7twl48qxY_I8gmAaOnXvrPgkfRbvBNpNe3X8iYcFG58y_zFHbzgu_zxIbrNwdUTtM-l1Pmeo5sA-Vtm2Agz3bDbYGptbSEr_lOMkmxJYIz0p8tWuQsB-FHg1K9BHOd3nsY6zQN7Ci_q-ZHG_ExlxBJOn8DX3-I2mW0Ddw9OSEWPoLjViovMgavcheIwxIobb8U6SHAeWi-_frnxwTMdZukZNcOZxrZktJTaOhdsiR4OCmVtTOaYmJochoo2m5SvDSjpCA",
|
||||
"token_type": "bearer",
|
||||
"expires_in": 43199,
|
||||
"scope": "clients.read password.write clients.secret clients.write uaa.admin clients.admin scim.write scim.read",
|
||||
"jti": "0da2797c39de4f308b0a4b8835325e5c"
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.cqu.ge.test;
|
||||
|
||||
public class Try {
|
||||
|
||||
/*
|
||||
public DataTable GetProficyData(String tagName, DateTime startDate, DateTime endDate) {
|
||||
DataSet ds = new DataSet();
|
||||
string queryString;
|
||||
System.Data.OleDb.OleDbDataAdapter adp;
|
||||
|
||||
using(System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection())
|
||||
{
|
||||
cn.ConnectionString = proficyConn.ConnectionString;
|
||||
cn.Open();
|
||||
|
||||
// always get a start value
|
||||
queryString = String.Format(
|
||||
"set samplingmode = lab\nselect value as theValue,Timestamp from ihrawdata where tagname = '{0}' AND timestamp between '{1}' and '{2}' order by timestamp",
|
||||
tagName.Replace("'", "\""), startDate.AddMinutes(-1), startDate);
|
||||
adp = new System.Data.OleDb.OleDbDataAdapter(queryString, cn);
|
||||
adp.Fill(ds);
|
||||
|
||||
// get the range
|
||||
queryString = string.Format(
|
||||
"set samplingmode = rawbytime\nselect value as theValue,Timestamp from ihrawdata where tagname = '{0}' AND timestamp between '{1}' and '{2}' order by timestamp",
|
||||
tagName.Replace("'", "\""), startDate, endDate);
|
||||
adp = new System.Data.OleDb.OleDbDataAdapter(queryString, cn);
|
||||
adp.Fill(ds);
|
||||
|
||||
// always get an end value
|
||||
queryString = string.Format(
|
||||
"set samplingmode = lab\nselect value as theValue,Timestamp from ihrawdata where tagname = '{0}' AND timestamp between '{1}' and '{2}' order by timestamp",
|
||||
tagName.Replace("'", "\""), endDate.AddMinutes(-1), endDate);
|
||||
adp = new System.Data.OleDb.OleDbDataAdapter(queryString, cn);
|
||||
adp.Fill(ds);
|
||||
|
||||
return ds.Tables[0];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.cqu.ge.test;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*@BelongsProject: GE_Migrating_data
|
||||
*@BelongsPackage: com.cqu.ge.test
|
||||
*@Author: markilue
|
||||
*@CreateTime: 2023-05-04 16:07
|
||||
*@Description: TODO
|
||||
*@Version: 1.0
|
||||
*/
|
||||
public class test1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Date cur1 = new Date();
|
||||
System.out.println(cur1);
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
cal1.setTime(cur1);
|
||||
cal1.add(Calendar.YEAR, -1);
|
||||
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
cal2.setTime(cur1);
|
||||
cal2.add(Calendar.SECOND, 1);
|
||||
|
||||
Date startTime = cal1.getTime();
|
||||
Date endTime = cal2.getTime();
|
||||
System.out.println(startTime);
|
||||
System.out.println(endTime);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue