Skip to content
Snippets Groups Projects
Commit c8ff205f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

modelId must be int

parent dcf82c16
No related branches found
No related tags found
1 merge request!5Frontend refactor
......@@ -20,15 +20,15 @@ var logger = require('../../logger');
function IdentifiedElement(javaObject) {
if (javaObject instanceof Alias) {
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.setModelId(javaObject.getModelId());
this.type = "ALIAS";
} else if (javaObject instanceof Reaction) {
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.setModelId(javaObject.getModelId());
this.type = "REACTION";
} else if (javaObject instanceof PointData) {
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.setModelId(javaObject.getModelId());
this.type = "POINT";
} else {
// identifier of the object to visualize
......@@ -36,7 +36,7 @@ function IdentifiedElement(javaObject) {
// which marker should be used to show this object
this.icon = javaObject.icon;
// on which model the element is located
this.modelId = javaObject.modelId;
this.setModelId(javaObject.modelId);
// what kind of object we are talking about
this.type = javaObject.type;
}
......@@ -66,9 +66,6 @@ function IdentifiedElement(javaObject) {
if (this.getId() === undefined || this.getId() === null) {
throw "Id not defined for element: " + javaObject;
}
if (this.modelId === undefined || this.modelId === null) {
throw "Model id not defined for element: " + javaObject;
}
}
/**
......@@ -106,6 +103,17 @@ IdentifiedElement.prototype.setId = function(id) {
this.id = id;
};
IdentifiedElement.prototype.getModelId = function() {
return this.id;
};
IdentifiedElement.prototype.setModelId = function(modelId) {
if (modelId === undefined || modelId === null) {
throw "ModelId is invalid";
}
this.modelId = parseInt(modelId);
};
/**
* Returns model identifier where element is placed.
*
......
......@@ -11,146 +11,146 @@ var chai = require('chai');
var assert = chai.assert;
var expect = chai.expect;
describe(
'IdentifiedElement',
function() {
beforeEach(function() {
logger.flushBuffer();
});
it("simple contructor", function() {
var javaObj = {
objectId : "31165",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var ie = new IdentifiedElement(javaObj);
assert.ok(ie);
assert.equal(31165, ie.getId());
assert.equal(269, ie.getModelId());
assert.equal("ALIAS", ie.getType());
assert.equal("marker/marker/marker_red_1.png", ie.getIcon());
});
it("point contructor", function() {
var javaObj = {
objectId : "Point2D.Double[117.685546875, 204.6923828125001]",
modelId : 269,
type : "POINT",
icon : "icons/comment.png"
};
var ie = new IdentifiedElement(javaObj);
assert.ok(ie);
assert.ok(ie.getPoint());
});
it("point contructor 2", function() {
var javaObj = {
objectId : "(117.685546875, 204.6923828125001)",
modelId : 269,
type : "POINT",
icon : "empty.png"
};
var ie = new IdentifiedElement(javaObj);
assert.ok(ie);
assert.ok(ie.getPoint());
});
it(
"contructor from alias",
function() {
var jsonString = '{"bounds":{"x":190,"y":44,"width":80,"height":40},"modelId":57,"idObject":18554}';
var javaObject = JSON.parse(jsonString);
var alias = new Alias(javaObject);
var ie = new IdentifiedElement(alias);
assert.ok(ie);
assert.equal(ie.getType(), "ALIAS");
});
it("contructor from Reaction", function() {
var javaObject = {
lines : [ {
start : Object,
end : Object,
type : "START"
}, {
start : Object,
end : Object,
type : "END"
}, {
start : Object,
end : Object,
type : "MIDDLE"
} ],
modelId : 319,
idObject : "13178",
centerPoint : {}
};
var reaction = new Reaction(javaObject);
var ie = new IdentifiedElement(reaction);
assert.ok(ie);
assert.equal(ie.getType(), "REACTION");
});
it("contructor from invalid object", function() {
var javaObject = [];
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Type not defined"));
});
it("contructor from PointData", function() {
var modelId = 3;
var point = new google.maps.Point(2, 3.45);
var pointData = new PointData(point, modelId);
var ie = new IdentifiedElement(pointData);
assert.ok(ie);
assert.equal(ie.getType(), "POINT");
});
it("contructor from invalid object 2", function() {
var javaObject = {
type : "unk_type"
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Unknown type"));
});
it("contructor from invalid object 3", function() {
var javaObject = {
type : "alias",
objectId : "el_id"
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Model id not defined"));
});
it("contructor from invalid object 4", function() {
var javaObject = {
type : "alias"
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Id not defined"));
});
it("contructor from artifitial obj", function() {
var javaObject = {
type : "alias",
objectId : "el_id",
modelId : "m_id"
};
var ie = new IdentifiedElement(javaObject);
var point = ie.getPoint();
expect(point).to.equal(null);
assert.equal(logger.getWarnings().length, 1);
});
});
describe('IdentifiedElement', function() {
beforeEach(function() {
logger.flushBuffer();
});
it("simple contructor", function() {
var javaObj = {
objectId : "31165",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var ie = new IdentifiedElement(javaObj);
assert.ok(ie);
assert.equal(31165, ie.getId());
assert.equal(269, ie.getModelId());
assert.equal("ALIAS", ie.getType());
assert.equal("marker/marker/marker_red_1.png", ie.getIcon());
});
it("point contructor", function() {
var javaObj = {
objectId : "Point2D.Double[117.685546875, 204.6923828125001]",
modelId : 269,
type : "POINT",
icon : "icons/comment.png"
};
var ie = new IdentifiedElement(javaObj);
assert.ok(ie);
assert.ok(ie.getPoint());
});
it("point contructor 2", function() {
var javaObj = {
objectId : "(117.685546875, 204.6923828125001)",
modelId : 269,
type : "POINT",
icon : "empty.png"
};
var ie = new IdentifiedElement(javaObj);
assert.ok(ie);
assert.ok(ie.getPoint());
});
it("contructor from alias", function() {
var jsonString = '{"bounds":{"x":190,"y":44,"width":80,"height":40},"modelId":57,"idObject":18554}';
var javaObject = JSON.parse(jsonString);
var alias = new Alias(javaObject);
var ie = new IdentifiedElement(alias);
assert.ok(ie);
assert.equal(ie.getType(), "ALIAS");
});
it("contructor from Reaction", function() {
var javaObject = {
lines : [ {
start : Object,
end : Object,
type : "START"
}, {
start : Object,
end : Object,
type : "END"
}, {
start : Object,
end : Object,
type : "MIDDLE"
} ],
modelId : 319,
idObject : "13178",
centerPoint : {}
};
var reaction = new Reaction(javaObject);
var ie = new IdentifiedElement(reaction);
assert.ok(ie);
assert.equal(ie.getType(), "REACTION");
});
it("contructor from invalid object", function() {
var javaObject = {
modelId : 2
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Type not defined"));
});
it("contructor from PointData", function() {
var modelId = 3;
var point = new google.maps.Point(2, 3.45);
var pointData = new PointData(point, modelId);
var ie = new IdentifiedElement(pointData);
assert.ok(ie);
assert.equal(ie.getType(), "POINT");
});
it("contructor from invalid object 2", function() {
var javaObject = {
modelId : 2,
type : "unk_type"
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Unknown type"));
});
it("contructor from invalid object 3", function() {
var javaObject = {
type : "alias",
objectId : "el_id"
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("ModelId is invalid"));
});
it("contructor from invalid object 4", function() {
var javaObject = {
type : "alias",
modelId : 4,
};
var code = function() {
new IdentifiedElement(javaObject);
};
assert.throws(code, new RegExp("Id not defined"));
});
it("contructor from artifitial obj", function() {
var javaObject = {
type : "alias",
objectId : "el_id",
modelId : "m_id"
};
var ie = new IdentifiedElement(javaObject);
var point = ie.getPoint();
expect(point).to.equal(null);
assert.equal(logger.getWarnings().length, 1);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment