Groovy: Could not find matching constructor - oop

Can anyone help me resolve why I am getting this run time error(cannot find the matching constructor) for the following class (JobStage). I tried to create an instance of the following class but it results in the following run time error.
class JobStage {
String name
StageType stageType
String transformationType
List<ImField> fields
TableAttribute tableAttributes
List<Connector> inputConnectors
List<Connector> outputConnectors
JobStageProperties stageProperties
JobStage(String name, StageType stageType, String transformationType,
List<ImField> fields,TableAttribute tableAttributes, List<Connector> inputConnectors,
List<Connector> outputConnectors, JobStageProperties stageProperties){
this.name = name
this.stageType = stageType
this.transformationType = transformationType
this.fields = fields
this.tableAttributes = tableAttributes
this.inputConnectors = inputConnectors
this.outputConnectors = outputConnectors
this.stageProperties = stageProperties
}
}
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.starling.informatica.dto.jobstage.JobStage(String, com.starling.informatica.dto.StageType, String, ArrayList, null, ArrayList, com.starling.informatica.dto.stageProperties.SourceRelationalStageProperties)
The error here assumes the TableAttribute class as null and igonres List<Connector> outputConnectors argument
I tried to create instance like so :
JobStageProperties stageProperties = TeradataSpecUtil.getSourceStageProperties()
List<ImField> fields = [new SourceField("integer","","customer_id","NULL","","10","0","","1","NOT A KEY","0","ELEMITEM","NO","11","0","0","0","10","0",""),
new SourceField("varchar","","customer_name","NULL","","50","0","","2","NOT A KEY","0","ELEMITEM","NO","0","0","0","11","50","10","")
]
List<Connector> inputConnectors = []
List<Connector> outputConnectors = [new Connector("customer_id","informatica_customer_source","Source Definition","customer_id","SQ_informatica_customer_source" ,"Source Qualifier"),
new Connector("customer_name","informatica_customer_source","Source Definition","customer_name","SQ_informatica_customer_source" ,"Source Qualifier")
]
TableAttribute tableAttribute = null
List<JobStage> expectedJobStage= [new JobStage("informatica_customer_source",
StageType.TERADATA_CONNECTOR, "Source Definition", fields,tableAttribute, inputConnectors,
outputConnectors, stageProperties)]

My Code is logically correct, the problem was with Intellij. The code ran successfully after I performed "Invalidate Caches and Restart".

Related

Writing a test class for Salesforce/APEX trigger

I have written down trigger in Salesforce APEX . It is working properly.
Code For Trigger is:
trigger SDRDemoUpdate_test on Event (before update) {
Map<ID,Event> records = New Map<ID,Event>([SELECT CreatedBy.Name FROM Event WHERE ID IN: trigger.new]);
for (Event obj :Trigger.new){
obj.SDR_Original_Demo__c = records.get(obj.id).CreatedBy.Name;
}
}
Now I am trying to write code for its test class. It is giving error on line saying object can not be parsed to String.
Code For Test Class is:
#isTest
public class originalDemo {
static testMethod void test_original_demo() {
Event obj = new Event();
obj.CreatedBy = 'Tom';
obj.Owner = 'Jack';
obj.What = 'Opportunity';
insert.obj;
userInfo.getName();
}
}
Looking forward to find out the solution. Any help would be appreciated.
Thanks
Your issue in these lines
obj.CreatedBy = 'Tom';
obj.Owner = 'Jack';
obj.What = 'Opportunity';
You tried to pass String to fields which required Id.
User user = [SELECT Id FROM User LIMIT 1];
obj.CreatedById = UserInfo.getUserId();
obj.OwnerId = user.Id;
obj.WhatId = opportunity.Id;

ReactiveMongo : How to write macros handler to Enumeration object?

I use ReactiveMongo 0.10.0, and I have following user case class and gender Enumeration object:
case class User(
_id: Option[BSONObjectID] = None,
name: String,
gender: Option[Gender.Gender] = None)
object Gender extends Enumeration {
type Gender = Value
val MALE = Value("male")
val FEMALE = Value("female")
val BOTH = Value("both")
}
And I declare two implicit macros handler:
implicit val genderHandler = Macros.handler[Gender.Gender]
implicit val userHandler = Macros.handler[User]
but, when I run application, I get following error:
Error:(123, 48) No apply function found for reactive.userservice.Gender.Gender
implicit val genderHandler = Macros.handler[Gender.Gender]
^
Error:(125, 46) Implicit reactive.userservice.Gender.Gender for 'value gender' not found
implicit val userHandler = Macros.handler[User]
^
Anybody know how to write macros handler to Enumeration object?
Thanks in advance!
I stumbled upon your question a few times searching for the same answer. I did it this way:
import myproject.utils.EnumUtils
import play.api.libs.json.{Reads, Writes}
import reactivemongo.bson._
object DBExecutionStatus extends Enumeration {
type DBExecutionStatus = Value
val Error = Value("Error")
val Started = Value("Success")
val Created = Value("Running")
implicit val enumReads: Reads[DBExecutionStatus] = EnumUtils.enumReads(DBExecutionStatus)
implicit def enumWrites: Writes[DBExecutionStatus] = EnumUtils.enumWrites
implicit object BSONEnumHandler extends BSONHandler[BSONString, DBExecutionStatus] {
def read(doc: BSONString) = DBExecutionStatus.Value(doc.value)
def write(stats: DBExecutionStatus) = BSON.write(stats.toString)
}
}
You have to create a read/write pair by hand and populate with your values.
Hope you already solved this issue given the question age :D

Associating workitem category to team area in RTC

I could create WorkItem categories but getting an error while associating it to the teamarea.Getting error in the line createcategory.getAssociatedTeamAreas().add(newTAHandle). I am not getting how to return a boolean object of ITeamAreaHandle inside add method. Getting the compilation error : java.lang.UnsupportedOperationException
Please help. Below is the related code.
IWorkItemClient wservice = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
ICategory createcategory = wservice.createCategory(area, categoryName, null);
wservice.saveCategory(createcat, null);
if (!teamArea.equals("NULL")){
List teamAreas = area.getTeamAreas();
List <teamareahandle> teamlist = teamAreas;
ITeamAreaHandle newTAHandle = findTeamAreaByName(teamlist,teamAreaName,monitor);
createcategory.getAssociatedTeamAreas().add(newTAHandle);
}
//Method findTeamAreaByName
private static ITeamAreaHandle findTeamAreaByName (List<teamareahandle> teamlist, String teamAreaID, IProgressMonitor monitor) throws TeamRepositoryException {
for (ITeamAreaHandle teamAreaHandle : teamlist) {
ITeamArea teamArea = (ITeamArea)teamRepository.itemManager().fetchCompleteItem(teamAreaHandle,ItemManager.DEFAULT,monitor);
if (teamAreaID.equals(teamArea.getName())) {
return teamAreaHandle;
}
}
return null;
}
This thread comments:
The API to associate categories with team areas is internal.
If you need it anyway, cast the ICategory to the internal Category interface and use e.g. category.setDefaultTeamArea(...).
You can set the associated ones using:
((Category) category).getTeamAreas().add(teamArea);
Try this:
ICategory category = workItemClient.createCategory(projectArea, categoryName, getProgressMonitor());
((Category) category).doSetDefaultTeamArea(teamArea);
((Category) category).setArchived(false); //if it is archived
workItemClient.saveCategory(category, getProgressMonitor());

Strange "Expected invocation on the mock at least once, but was never performed" error when I am setting up the Mock

I'm getting this error from Moq via NUnit, and it doesn't make much in the way of sense to me.
"Expected invocation on the mock at least once, but was never performed: x => x.DeleteItem(.$VB$Local_item)"
"at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable1 setups, IEnumerable1 actualCalls, Expression expression, Times times, Int32 callCount)
at Moq.Mock.VerifyCalls(Interceptor targetInterceptor, MethodCall expected, Expression expression, Times times)
at Moq.Mock.Verify[T](Mock mock, Expression1 expression, Times times, String failMessage)
at Moq.Mock1.Verify(Expression`1 expression)
at PeekABookEditor.UnitTests.ItemBrowsing.Can_Delete_Item() in C:\Projects\MyProject\MyProject.UnitTests\Tests\ItemBrowsing.vb:line 167"
Very similar code works well in C#, so the error might be minor and syntactical on my part.
Here's my code:
<Test()> _
Public Sub Can_Delete_Item()
'Arrange: Given a repository containing some item...
Dim mockRepository = New Mock(Of IItemsRepository)()
Dim item As New Item With {.ItemID = "24", .Title = "i24"}
mockRepository.Setup(Function(x) x.Items).Returns(New Item() {item}.AsQueryable())
'Act ... when the user tries to delete that product
Dim controller = New ItemsController(mockRepository.Object)
Dim result = controller.Delete(24)
'Assert ... then it's deleted, and the user sees a confirmation
mockRepository.Verify(Sub(x) x.DeleteItem(item))
result.ShouldBeRedirectionTo(New With {Key .action = "List"})
Assert.AreEqual(DirectCast(controller.TempData("message"), String), "i24 was deleted")
End Sub
The guilty line appears to be "mockRepository.Verify(Sub(x) x.DeleteItem(item))"
Any thoughts on how to fix this?
Working C# code isn't the exact same, but here it is:
[Test]
public void Can_Delete_Product()
{
// Arrange: Given a repository containing some product...
var mockRepository = new Mock<IProductsRepository>();
var product = new Product { ProductID = 24, Name = "P24"};
mockRepository.Setup(x => x.Products).Returns(
new[] { product }.AsQueryable()
);
// Act: ... when the user tries to delete that product
var controller = new AdminController(mockRepository.Object);
var result = controller.Delete(24);
// Assert: ... then it's deleted, and the user sees a confirmation
mockRepository.Verify(x => x.DeleteProduct(product));
result.ShouldBeRedirectionTo(new { action = "Index" });
controller.TempData["message"].ShouldEqual("P24 was deleted");
}
In your VB test method, you create Item with a string ItemID = "24", but you call the controller.Delete method with an integer value of 24.
Check your controller code and see if the type discrepancy results in the item not being identified correctly, so either DeleteItem is not called at all, or is called with a different Item.

JSON Grail Groovy Update SQL

Using a Groovy script with grails and want to do an update to a record in the database. I do the basic get the object from JSON and convert it to the Domain class and then do save() on it. From what I understand since I am new to Groovy and grails the save should update if the "id" is already there. But I don't get that, I get the standard SQL error of "Duplicate entry '1' for key 'PRIMARY'". How do I fix this?
def input = request.JSON
def instance = new Recorders(input)
instance.id = input.getAt("id")
instance.save()
and my domain is:
class Recorders {
Integer sdMode
Integer gsmMode
static mapping = {
id generator: "assigned"
}
static constraints = {
sdMode nullable: true
gsmMode nullable: true
}
}
Instead of doing a new Recorders(input), you probably ought to get it:
def input = request.JSON
def instance = Recorders.get(input.getAt('id'))
instance.properties = input
instance.save()
Edit
(From your comment) If it doesn't exist and you want to insert it:
def input = request.JSON
def id = input.getAt('id')
def instance = Recorders.get(id)
if(!instance) {
instance = new Recorders(id: id)
}
instance.properties = input
instance.save()
I don't use assigned id generators much, so I'm not sure if Grails will bind the id automatically (since it's expecting it to be assigned). If it does, you can probably remove the id: id from the Recorders() constructor.