ALL time groovy compilation error - groovy

All time am getting below error message in groovy...
Could not understand whats causing this " Unexpected token error" ????
I used to think only PERL give bad compilation error,now groovy outperforming it..
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
D:\Playground\groovy\release-b-work\cmd_line_soapui\trial.groovy: 12:
unexpected token: myrunner # line 12, column 1.
myrunner.setProjectFile("D:\soapui-release-B\try.xml");
^
1 error
Code taken from comment;
import com.eviware.soapui.SoapUIProTestCaseRunner;
import com.eviware.soapui.support.*;
import com.eviware.soapui.model.*;
import com.eviware.soapui.impl.wsdl.*;
import com.eviware.soapui.*;
class trial {
def myrunner = new com.eviware.soapui.SoapUIProTestCaseRunner();
myrunner.setProjectFile("D:\soapui-release-B\try.xml");
myrunner.setTestSuite("MediaAssetServiceTestSuite");
myrunner.setTestCase("createMediaAsset TestCase");
myrunner.run();
}

You need to put your code in a method
You can't just add code into a class at class level
Try:
import com.eviware.soapui.SoapUIProTestCaseRunner;
import com.eviware.soapui.support.*;
import com.eviware.soapui.model.*;
import com.eviware.soapui.impl.wsdl.*;
import com.eviware.soapui.*;
class trial {
def someMethod() {
def myrunner = new com.eviware.soapui.SoapUIProTestCaseRunner();
myrunner.setProjectFile("D:\soapui-release-B\try.xml");
myrunner.setTestSuite("MediaAssetServiceTestSuite");
myrunner.setTestCase("createMediaAsset TestCase");
myrunner.run();
}
}

Related

Scriptrunner/ Copying Project while logged-in as another user

I want to use my script, so that it will be executed by someone who is not me, but another user (ServiceUser) in the Jira Instance.
This is my functioning code, but I do not know how to make someone else execute it.
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Logger
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.bc.project.ProjectCreationData
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.project.type.ProjectTypeKey
// the key for the new project
def projectKey = "EXA987"
def projectName = "EXA987"
def log = Logger.getLogger("com.onresolve.jira.groovy.MyScript")
Thread executorThread = new Thread(new Runnable() {
void run() {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : "SWTEMP",
(CopyProject.FIELD_TARGET_PROJECT) : projectKey,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : projectName,
(CopyProject.FIELD_COPY_VERSIONS) : false,
(CopyProject.FIELD_COPY_COMPONENTS) : false,
(CopyProject.FIELD_COPY_ISSUES) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
log.warn("Couldn't create project: $errorCollection")
}
else {
def util = ComponentAccessor.getUserUtil()
def adminsGroup = util.getGroupObject("jira-administrators")
assert adminsGroup // must have jira-administrators group defined
def admins = util.getAllUsersInGroups([adminsGroup])
assert admins // must have at least one admin
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(util.getUserByName(admins.first().name))
copyProject.doScript(inputs)
}
}
})
executorThread.start()
I stumbled upon other codes, using things like
def oldLoggedInUser = jiraAuthenticationContext.getLoggedInUser()
jiraAuthenticationContext.setLoggedInUser(serviceUser)
jiraAuthenticationContext.setLoggedInUser(oldLoggedInUser)
but it was not succesful for me.
I have used following solution to change user during script execution:
def authContext = ComponentAccessor.getJiraAuthenticationContext();
def currentUser = authContext.getLoggedInUser();
def superuser=ComponentAccessor.getUserManager().getUserByKey("ANOTHER_USER_ACCOUNT")
authContext.setLoggedInUser(superuser);
// < do the needed work>
authContext.setLoggedInUser(currentUser);
I had first issues as my used another account had not needed Jira access rights (and I got funny "user must be logged in" errors)

Kotlin - menuInflater cannot find reference of the xml file

I am trying to add create option menu to my activity, however the android-studio sent me this error
Unresolved reference: chat_app_menu
Here is my code in Kotlin
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.chat_app_menu)
return true
}
The line with menuInflater.inflate(R.menu.chat_app_menu) show me the error Unresolved reference: chat_app_menu
However, I have been create the resource file chat_app_menu.xml under res\menu\
Here are my import files
package com.example.chat_app
import android.R
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuInflater
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.auth.FirebaseAuth
My file directory:
What should I do to disable this error to make the app work?
Use your com.example.chat_app.R instead of android.R
import com.example.chat_app.R

Attempting to assert 500 error, but response is null when conditions are met

When I automated this I came to know that the 500 error that is thrown is given by server. But at our code level we have handled the exception and the response =null
So when I tried to assert with response.status==500 it fails as the response is altogether null.
package test
import geb.spock.GebReportingSpec
import groovyx.net.http.RESTClient
import net.sf.json.JSON
import org.apache.log4j.Logger
import spock.lang.Specification
import spock.lang.Unroll
class EventsAPITest extends GebReportingSpec{
static Logger logger = Logger.getLogger("EventsAPITest");
#Unroll
def "Call calendar event for Invalid Location id 110 throws groovyx.net.http.HttpResponseException"() {
given:
RESTClient restClient = new RESTClient("https://test-api2.club-os.com")
def response=restClient.get(path: '/authenticate',requestContentType: JSON,query:[
'username': 'apiuser',
'password':'apipassword',
])
def authToken=response.data.token
logger.info"Token:" +authToken
restClient.defaultRequestHeaders['Authorization'] = authToken
def locationId=110
when:
response=restClient.get(path: '/locations/'+locationId+'/events',requestContentType: JSON, query:[
'startTimeStartAt': '2018-05-25T17:00:00.000Z',
'startTimeEndAt':'2018-06-01T17:00:00.000Z',
'eventTypeId' : 2 ])
then:
thrown groovyx.net.http.HttpResponseException
logger.info"Response: "+ response
// assert response.data.errorMessage=="Error"
assert response.status == 500
//assert response.status == 500
// assert response.data.errorMessage == "An unknown error occurred"
}
I would like to be able to assert a 500 error and have that returned.
This is not spock-specific. Your code throws an exception, therefore it cannot return a value.
UPDATE after kriegaex's advice in the comments.
By assigning the result of the thrown groovyx.net.http.HttpResponseException expression to a variable, you can access the exception's state. This exception's API is documented here: http://javadox.com/org.codehaus.groovy.modules.http-builder/http-builder/0.6/groovyx/net/http/HttpResponseException.html.
You can access the statusCode property directly, and you have a response property too. That's everything you need to test your conditions.
This is the resulting code:
import geb.spock.GebReportingSpec
import groovyx.net.http.RESTClient
import net.sf.json.JSON
import org.apache.log4j.Logger
import spock.lang.Specification
import spock.lang.Unroll
class EventsAPITest extends GebReportingSpec{
static Logger logger = Logger.getLogger("EventsAPITest");
#Unroll
def "Call calendar event for Invalid Location id 110 throws groovyx.net.http.HttpResponseException"() {
given:
RESTClient restClient = new RESTClient("https://test-api2.club-os.com")
def response=restClient.get(path: '/authenticate',requestContentType: JSON,query:[
'username': 'apiuser',
'password':'apipassword',
])
def authToken=response.data.token
logger.info"Token:" +authToken
restClient.defaultRequestHeaders['Authorization'] = authToken
def locationId=110
when:
response=restClient.get(path: '/locations/'+locationId+'/events',requestContentType: JSON, query:[
'startTimeStartAt': '2018-05-25T17:00:00.000Z',
'startTimeEndAt':'2018-06-01T17:00:00.000Z',
'eventTypeId' : 2 ])
then:
//Here, assign the exception to a variable.
def e= thrown groovyx.net.http.HttpResponseException
logger.info"Response: "+ e.response
// assert response.data.errorMessage=="Error"
assert e.response.status == 500
//assert response.status == 500
// assert response.data.errorMessage == "An unknown error occurred"
}

Spock unrecognized block label: given

I have the following spock test.
package com.arch.unit.category
import com.arch.domain.category.Category
import com.arch.domain.category.CategoryRepository
import com.arch.handler.category.CategoryCreateHandler
import com.arch.message.command.category.CategoryCreateCommand
import spock.lang.Specification
def "create category expected succeed"() {
given:
def command = new CategoryCreateCommand("Php")
and:
categoryRepository.save(_ as Category) >> new Category("Php")
when:
def response = handler.execute(command)
then:
response.code == 100
}
It is not working. I get an error "Error:(20, 16) Groovyc: Unrecognized block label: given"
My dependencies
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.codehaus.groovy:groovy-all')
testCompile('org.spockframework:spock-core:1.1-groovy-2.4-rc-4')
testCompile('org.spockframework:spock-spring:1.1-groovy-2.4-rc-4')
Environment : Windows, Java8, Intellij Community Edition
It's worked my mac before. But now not working.

null pointer exception in soapui groovy script

I am receiving this null pointer exception and not sure how to resolve/debug it. The script contains a class with two methods. Code is doing what it is supposed to do. Any pointers on geeting started to resolve this?
java.lang.NullPointerException
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:154)
at com.eviware.soapui.model.testsuite.TestStep$run.call(Unknown Source)
at Script48.run(Script48.groovy:22)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.assertScript(GroovyScriptAssertion.java:116)
at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.internalAssertResponse(GroovyScriptAssertion.java:128)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion.assertResponse(WsdlMessageAssertion.java:150)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest.assertResponse(WsdlTestRequest.java:176)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.propertyChange(WsdlTestRequestStep.java:339)
at com.eviware.soapui.impl.wsdl.support.assertions.AssertionsSupport.propertyChange(AssertionsSupport.java:79)
at java.beans.PropertyChangeSupport.fire(Unknown Source
Script looks like this.
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
context.setProperty("searchChange", new searchChange())
class searchChange{
def search(a,b,TCRunner){
def search_TestCase = TCRunner.testCase.testSuite.getTestCaseByName("TestCaseName")
search_TestCase.setPropertyValue("a", a)
search_TestCase.setPropertyValue("b", b)
search_TestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
}
def runner(tCase,mExchange){
new WsdlTestCaseRunner( tCase, new StringToObjectMap() );
}
}
When using the above class,the line(groovy:22) in code that throws exception is
scripts.testCases["Library"].testSteps["Lib"].run(context.getTestRunner(),context)

Resources