Skip to content
Snippets Groups Projects
Commit 8678f751 authored by PICHON's avatar PICHON
Browse files

Merging

parents d8f672ac 02049c13
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,9 @@ import static org.mockito.Mockito.when;
import java.lang.reflect.Array;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import fr.esrf.TangoApi.DeviceProxy;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
......@@ -140,14 +142,13 @@ public class TangoParserTest {
private static final String wDoubleSQRTParser = "C";
// private static TangoSource mockSource = Mockito.mock(TangoSource.class,
// withSettings().verboseLogging());
//private static TangoSource mockSource = Mockito.mock(TangoSource.class, withSettings().verboseLogging());
private static TangoSource mockSource = Mockito.mock(TangoSource.class);
private static SourceManager mngr = Mockito.spy(SourceManager.class);
@BeforeClass
public static void setUp() throws DevFailed {
public static void setUp() throws DevFailed, InterruptedException {
System.setProperty("org.tango.server.checkalarms", "false");
// assertThat(System.getProperty("TANGO_HOST"), notNullValue());
//System.setProperty("TANGO_HOST", "192.168.56.101:10000");
......@@ -159,8 +160,7 @@ public class TangoParserTest {
@Override
public Boolean answer(final InvocationOnMock invocation) {
System.out.println("mock add source " + invocation);
@SuppressWarnings("unchecked")
final Map<String, String> arg = invocation.getArgumentAt(1, Map.class);
@SuppressWarnings("unchecked") final Map<String, String> arg = invocation.getArgumentAt(1, Map.class);
for (final String s : arg.keySet()) {
if (s.contains("spec")) {
return true;
......@@ -190,8 +190,7 @@ public class TangoParserTest {
// create device in tangodb
System.out.println("create device in tango db");
final Database db = ApiUtil.get_db_obj();
db.add_device(deviceNameParser, TangoParser.class.getSimpleName(),
TangoParser.class.getSimpleName() + "/" + INSTANCE_NAME);
db.add_device(deviceNameParser, TangoParser.class.getSimpleName(), TangoParser.class.getSimpleName() + "/" + INSTANCE_NAME);
// configure properties
final DbDatum[] dbDatum = new DbDatum[7];
......@@ -204,11 +203,14 @@ public class TangoParserTest {
"value1FloatSpec," + floatSpectrumPub, "value1ShortSpec," + shortSpectrumPub,
"value1IntSpec," + intSpectrumPub,};
final String[] propOutputNames = new String[] { doubleParser + ",value1Double>2",
final String[] propOutputNames = new String[]{
doubleParser + ",value1Double>2",
"DevString " + stringParser + ",value1String+\"test\"",
"DevBoolean " + booleanParser + ",!value1Boolean", "DevShort " + shortParser + ",value1Short*2",
"DevBoolean " + booleanParser + ",!value1Boolean",
"DevShort " + shortParser + ",value1Short*2",
"DevBoolean " + shortParserBooleanExtract + ",boolextract(value1Short,3)",
"DevLong " + longParser + ",value1Long^5", "DevFloat " + floatParser + ",value1Float+2",
"DevLong " + longParser + ",value1Long^5",
"DevFloat " + floatParser + ",value1Float+2",
"SPECTRUM DevString " + stringSpectrumParser + ",add(value1StringSpec,\"aa\")",
// "IMAGE DevDouble " + doubleImgParser + ",value1DoubleIm*2",
......@@ -231,8 +233,7 @@ public class TangoParserTest {
"SPECTRUM DevShort " + shortSpectrumParserMul + ",mul(value1ShortSpec,value1ShortSpec)",
//Spectrum manipulation
"DevDouble " + doubleSpectrumParserElem + ",getSpectrumElem(value1DoubleSpec, value1Short)",
"SPECTRUM DevDouble " + doubleSpectrumParserSet
+ ",setSpectrumElem(value1DoubleSpec,value1Short,value1Double)",
"SPECTRUM DevDouble " + doubleSpectrumParserSet + ",setSpectrumElem(value1DoubleSpec,value1Short,value1Double)",
"DevLong " + doubleSpectrumParserSize + ",getSpectrumSize(value1DoubleSpec)",
"SPECTRUM DevDouble " + doubleSpectrumParserRep + ",replicate(value1Double,value1Short)",
// Soustraction
......@@ -273,18 +274,22 @@ public class TangoParserTest {
// Std
"DevDouble " + doubleSpectrumParserStd + ",std(1,2,3,4,5,6,7,8,9,10)",
// Test Order
orderParser + ",value1DoubleW/value2DoubleW", orderComplexeParser
+ ",(42*(value1DoubleW/(value1DoubleW*value2DoubleW))*(value1Short-value1Long+(value1Short/value1Long)))/(value1DoubleW/value2DoubleW*value1Short/value1Long)" };
orderParser + ",value1DoubleW/value2DoubleW",
orderComplexeParser
+ ",(42*(value1DoubleW/(value1DoubleW*value2DoubleW))*(value1Short-value1Long+(value1Short/value1Long)))/(value1DoubleW/value2DoubleW*value1Short/value1Long)"
};
final String[] propInputNames = new String[] { "A,value1DoubleW=A+1",
"SPECTRUM DevDouble B,value1DoubleWSpec=B*2", "C,value1DoubleW=sqrt(C)",
"D,value2DoubleW=(((D^2)/2)>2) || 0", "X,value1DoubleW=X+2", "X,value2DoubleW=X+2" };
final String[] propInputNames = new String[]{"A,value1DoubleW=A+1", "SPECTRUM DevDouble B,value1DoubleWSpec=B*2",
"C,value1DoubleW=sqrt(C)", "D,value2DoubleW=(((D^2)/2)>2) || 0", "X,value1DoubleW=X+2",
"X,value2DoubleW=X+2"};
final String[] propIONames = new String[] { "DevDouble IO;value1DoubleW+value1Short; value1DoubleW=IO+1",
final String[] propIONames = new String[]{
"DevDouble IO;value1DoubleW+value1Short; value1DoubleW=IO+1",
ioParserComplex
+ ";0.5*12398.42/lambda/(sin(0.5*atan(150.0/value1DoubleW)));lambda=12398.42/(value2DoubleW*1000.0);value1DoubleW=150.0/tan(2.0*asin(lambda/2.0/IOComplex))",
"SPECTRUM DevDouble IOSpectrum;[1, 2, 3, 4, 5, 6];value1DoubleWSpec=IOSpectrum/2",
"DevDouble IOSpectrumFactor;A;value1DoubleWSpec=[1, 2, 3, 4, 5, 6]*IOSpectrumFactor" };
"DevDouble IOSpectrumFactor;A;value1DoubleWSpec=[1, 2, 3, 4, 5, 6]*IOSpectrumFactor"
};
dbDatum[0] = new DbDatum("AttributeNames", propAttributeNames);
dbDatum[1] = new DbDatum("OutputNames", propOutputNames);
......@@ -302,32 +307,31 @@ public class TangoParserTest {
ServerManager.getInstance().addClass(TangoParser.class.getSimpleName(), TangoParser.class);
ServerManager.getInstance().start(new String[]{INSTANCE_NAME}, TangoParser.class.getSimpleName());
boolean launched = false;
boolean launched = true;
long maximumTime = 20000;
long timer = maximumTime;
long stepTime = 1500;
DevState startState = DevState.UNKNOWN;
while (!launched && timer > 0) {
final DeviceProxy tangoParser = new DeviceProxy(deviceNameParser);
DevState startState = tangoParser.state();
try {
Thread.sleep(stepTime);
} catch (final InterruptedException e) {
while (startState.equals(DevState.INIT) && timer > 0) {
TimeUnit.MILLISECONDS.sleep(stepTime);
startState = tangoParser.state();
System.out.println("State = " + startState);
timer -= stepTime;
}
try {
final TangoAttribute tangoParser = new TangoAttribute(deviceNameParser + "/state");
startState = (DevState) tangoParser.read();
System.out.println("State readed : " + startState);
launched = startState == DevState.ON;
launched = timer > 0;
} catch (DevFailed e) {
launched = false;
}
timer -= stepTime;
DevFailedUtils.printDevFailed(e);
throw e;
}
if (launched) {
System.out.println("Device started in " + Double.toString((maximumTime - timer) / 1000.0) + " seconds.");
System.out.println("Device state: " + startState.toString());
System.out.println("Device started in " + Double.toString(TimeUnit.MILLISECONDS.toSeconds(maximumTime - timer)) + " seconds.");
System.out.println("Device state: " + tangoParser.state());
System.out.println(tangoParser.status());
} else {
System.out.println("Device failed to start." + startState.toString());
System.out.println("Device start up took too much time, aborting");
}
System.out.println("Set up done");
......@@ -346,8 +350,7 @@ public class TangoParserTest {
// System.err.println("device is not ON, status:\n" + status);
// System.err.println("errors attribute value:\n"
// + Arrays.toString(proxy.read_attribute("errors").extractStringArray()));
// DevFailedUtils.throwDevFailed("INIT_ERROR", DeviceState.toString(state) + ":"
// + status);
// DevFailedUtils.throwDevFailed("INIT_ERROR", DeviceState.toString(state) + ":" + status);
// }
}
......@@ -966,8 +969,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecAdd() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserAdd);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserAdd);
r.setValue(new Integer[]{1, 2, 3, 4, 5});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
......@@ -1009,8 +1012,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecCos() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserCos);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserCos);
r.setValue(new Integer[]{0, 1});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
// final TangoAttribute pub = new TangoAttribute(intSpectrumPub);
......@@ -1024,8 +1027,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecDiv() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserDiv);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserDiv);
r.setValue(new Integer[]{2, 4, 6, 8, 10});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
// final TangoAttribute pub = new TangoAttribute(intSpectrumPub);
......@@ -1039,8 +1042,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecFft() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserFft);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserFft);
r.setValue(new Integer[]{1, 2, 3, 4});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
......@@ -1074,8 +1077,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecLog() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserLog);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserLog);
r.setValue(new Integer[]{1, 2});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
......@@ -1090,8 +1093,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecMul() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserMul);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserMul);
r.setValue(new Integer[]{2, 4, 6, 8, 10});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
......@@ -1106,8 +1109,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecSin() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserSin);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserSin);
r.setValue(new Integer[]{0, 1});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
// final TangoAttribute pub = new TangoAttribute(intSpectrumPub);
......@@ -1121,8 +1124,8 @@ public class TangoParserTest {
@Test
public void testReadIntSpecSub() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub), AttrDataFormat.SPECTRUM,
intSpectrumParserSub);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(intSpectrumPub),
AttrDataFormat.SPECTRUM, intSpectrumParserSub);
r.setValue(new Integer[]{2, 4, 6, 8, 10});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(intSpectrumPub));
// final TangoAttribute pub = new TangoAttribute(intSpectrumPub);
......@@ -1210,8 +1213,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecAdd() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserAdd);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserAdd);
r.setValue(new Short[]{1, 2, 3, 4, 5});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
// final TangoAttribute pub = new TangoAttribute(shortSpectrumPub);
......@@ -1225,8 +1228,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecCos() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserCos);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserCos);
r.setValue(new Short[]{0, 1});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
// final TangoAttribute pub = new TangoAttribute(shortSpectrumPub);
......@@ -1240,8 +1243,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecDiv() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserDiv);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserDiv);
r.setValue(new Short[]{2, 4, 6, 8, 10});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
......@@ -1256,8 +1259,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecFft() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserFft);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserFft);
r.setValue(new Short[]{1, 2});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
......@@ -1273,8 +1276,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecLog() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserLog);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserLog);
r.setValue(new Short[]{1, 2});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
......@@ -1289,8 +1292,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecMul() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserMul);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserMul);
r.setValue(new Short[]{2, 4, 6, 8, 10});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
......@@ -1306,8 +1309,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecSin() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserSin);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserSin);
r.setValue(new Short[]{0, 1});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
......@@ -1322,8 +1325,8 @@ public class TangoParserTest {
@Test
public void testReadShortSpecSub() throws DevFailed {
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub), AttrDataFormat.SCALAR,
shortSpectrumParserSub);
final AttributeResult r = new AttributeResult(deviceNameParser, getAtt(shortSpectrumPub),
AttrDataFormat.SCALAR, shortSpectrumParserSub);
r.setValue(new Short[]{2, 3, 4, 5, 6});
doReturn(r).when(mockSource).getResult(deviceNameParser, getAtt(shortSpectrumPub));
......@@ -1443,8 +1446,8 @@ public class TangoParserTest {
}
/**
* Test command setExpression for READ attribute. The name of the test start by
* z because we want execute it at the end to not affect other test.
* Test command setExpression for READ attribute. The name of the test start
* by z because we want execute it at the end to not affect other test.
*
* @throws DevFailed
*/
......@@ -1471,8 +1474,9 @@ public class TangoParserTest {
}
/**
* Test command setExpression for WRITE attribute. The name of the test start by
* z because we want execute it at the end to not affect other test.
* Test command setExpression for WRITE attribute. The name of the test
* start by z because we want execute it at the end to not affect other
* test.
*
* @throws DevFailed
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment