Hi,

I'm developing an extensión for Jenkins, that consists of a new WEB API 
aimed to provide our ALM tooling with tailored operations on Jenkins. The 
starting point for me was this guide 
<https://www.jenkins.io/doc/developer/handling-requests/json/>, which I 
have reproduced step by step.

After manual tests of a bare minimum API, I concluded that the extension 
was working and ready for further development. 

To speed up development and testing, I have also prepared a canary test in 
JUnit, following the previous guide (linked above) and this other 
<https://www.jenkins.io/doc/developer/testing/> to feed test with 
*@LocalData.*

The firsts times I run the JUnit, it worked. Test passed. So, I was able to 
run *mvn clean packge* and complete the build executing (and passing) all 
tests

Today, I did open the IDE, run the same maven goals to ensure that 
everything was ok (a  routine of mine), but tests failed due to a *404 Not 
Found*

Here the stacktrace









































*Test timeout disabled.=== Starting 
test_ping(net.corp.jenkins.plugins.almapirest.AlmApiTest)   0.152 [id=1]   
 INFO    o.jvnet.hudson.test.WarExploder#explode: Picking up existing 
exploded jenkins.war at 
/home/user/Desarrollo/workspace-11/jenkins-plugins/imi-alm-jenkinsplugin-almapirest/target/jenkins-for-test
  
 0.522 [id=1]    INFO    o.jvnet.hudson.test.JenkinsRule#createWebServer: 
Running on http://localhost:34866/jenkins/   1.057 [id=33]    INFO   
 jenkins.InitReactorRunner$1#onAttained: Started initialization   2.433 
[id=38]    INFO    hudson.PluginManager#considerDetachedPlugin: Loading a 
detached plugin as a dependency: 
/tmp/jenkins11162667569266280008/plugins/bouncycastle-api.jpi   2.545 
[id=38]    INFO    hudson.PluginManager#considerDetachedPlugin: Loading a 
detached plugin as a dependency: 
/tmp/jenkins11162667569266280008/plugins/command-launcher.jpi   2.554 
[id=38]    INFO    hudson.PluginManager#considerDetachedPlugin: Loading a 
detached plugin as a dependency: 
/tmp/jenkins11162667569266280008/plugins/jdk-tool.jpi   2.566 [id=38]   
 INFO    hudson.PluginManager#considerDetachedPlugin: Loading a detached 
plugin as a dependency: /tmp/jenkins11162667569266280008/plugins/jaxb.jpi  
 2.791 [id=38]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed 
all pluginsWARNING: An illegal reflective access operation has 
occurredWARNING: Illegal reflective access by 
com.google.inject.internal.cglib.core.$ReflectUtils$2 
(file:/home/user/.m2/repository/com/google/inject/guice/4.0/guice-4.0.jar) 
to method 
java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)WARNING:
 
Please consider reporting this to the maintainers of 
com.google.inject.internal.cglib.core.$ReflectUtils$2WARNING: Use 
--illegal-access=warn to enable warnings of further illegal reflective 
access operationsWARNING: All illegal access operations will be denied in a 
future release   6.538 [id=36]    INFO   
 jenkins.InitReactorRunner$1#onAttained: Prepared all plugins   6.577 
[id=34]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all 
plugins   6.590 [id=36]    INFO    jenkins.InitReactorRunner$1#onAttained: 
Augmented all extensions   7.742 [id=37]    INFO   
 jenkins.InitReactorRunner$1#onAttained: System config loaded   7.743 
[id=37]    INFO    jenkins.InitReactorRunner$1#onAttained: System config 
adapted   7.743 [id=37]    INFO    jenkins.InitReactorRunner$1#onAttained: 
Loaded all jobs   7.748 [id=31]    INFO   
 jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs 
updated   7.858 [id=35]    INFO    jenkins.InitReactorRunner$1#onAttained: 
Completed initialization  10.414 [id=1]    INFO   
 n.o.j.p.almapirest.AlmApiTest#logJenkinsWebResponse: <html><body><h1>404 
Not Found</h1><p>Stapler processed this HTTP request as follows, but 
couldn't find the resource to consume the request<pre>-&gt; 
evaluate(&lt;hudson.model.Hudson@5d1c17df&gt; 
:hudson.model.Hudson,"/alm-api/ping")-&gt; 
evaluate(((StaplerProxy)&lt;hudson.model.Hudson@5d1c17df&gt;).getTarget(),"/alm-api/ping")-&gt;
 
evaluate(&lt;hudson.model.Hudson@5d1c17df&gt;.getDynamic("alm-api",...),"/ping")
  
          [email protected]("alm-api",...)==null. 
Back tracking.-&gt; 
evaluate(((StaplerFallback)&lt;hudson.model.Hudson@5d1c17df&gt;).getStaplerFallback(),"/alm-api/ping")-&gt;
 
evaluate(&lt;hudson.model.AllView@2c546831[view/all/]&gt; 
:hudson.model.AllView,"/alm-api/ping")-&gt; 
evaluate(&lt;hudson.model.AllView@2c546831[view/all/]&gt;.getDynamic("alm-api",...),"/ping")
  
          
hudson.model.AllView@2c546831[view/all/].getDynamic("alm-api",...)==null. 
Back tracking.<font color=red>-&gt; No matching rule was found on 
&lt;hudson.model.AllView@2c546831[view/all/]&gt; for 
"/alm-api/ping"</font></pre><p>&lt;hudson.model.AllView@2c546831[view/all/]&gt; 
has the following URL mappings, in the order of preference:<ol><li>If path 
ends without '/' insert it<li>*

When I run *mvn hpi:run* to do manual testing, the extension works and the 
endpoints are accessible. I also check that *work/plugins *contain my 
extension packaged as hpi. 

I have realised that when I run *JenkinsRule* , a new Jenkins is downloaded 
and deployed in */tmp* and static content is deployed in 
*{projectDir}/target/jenkins-for-test*. But my plugin is not in any of 
these folders. So my guess is that the failure is caused because my source 
code is not loaded properly during the test execution.

Does anyone know why my JUnit' no longer load and finds my extension?  

It should be something related to my local environment or workspace, but I 
don't know what could have changed since the last time tests worked.

The test code is 
*@Rule*
*public JenkinsRule jenkinsRule = new JenkinsRule();*

*public void test_ping() throws Exception {*
*    JenkinsRule.WebClient webClient = jenkinsRule.createWebClient();*
*    JenkinsRule.JSONWebResponse response = 
webClient.getJSON("alm-api/ping");*
*    logJenkinsWebResponse(response);*
*    assertThat(response.getStatusCode(), is(200));*
*    assertThat(response.getJSONObject().get("pong"), notNullValue());*
*}*
*private static void logJenkinsWebResponse(JenkinsRule.JSONWebResponse 
response) {*
*   try {*
*      LOG.info(response.getJSONObject().toString(2,2));*
*   }catch(JSONException ex) {*
*      LOG.info(response.getContentAsString());*
*   }*
*}*

*No JUnit @RunWith specified*

The production code of the API is

*@Extension*
*public class AlmApi implements RootAction {*

*    protected static final String ALM_API_NAME = "alm-api";*

*    @Override*
*    public String getIconFileName() { **return null; **}*

*    @Override*
*    public String getDisplayName() { **return null; **}*

*    @Override*
*    public String getUrlName() { **return ALM_API_NAME; **}*

*   @GET*
*   @WebMethod(name = "ping")*
*   public JsonHttpResponse ping() {*
*     JSONObject response = JSONObject.fromObject(new 
PongDTO(Instant.now()));*
*     return new JsonHttpResponse(response, 200);*
*   }*

*}*

Thank you in advance!



-- 













Advertiment legal: la informació d’aquest missatge de correu 
electrònic és confidencial i s’adreça exclusivament al destinatari previst. 
Si ha rebut el missatge per error, sisplau, notifiqui-ho al remitent i 
esborri’l sense copiar-lo, enregistrar-lo ni distribuir-lo.


Advertencia 
legal: la información de este mensaje de correo electrónico es confidencial 
y se dirige exclusivamente al destinatario previsto. Si usted ha recibido 
el mensaje por error, por favor, notifíquelo al remitente y bórrelo sin 
copiarlo, grabarlo ni distribuirlo.


Legal warning: the information 
contained in this e-mail message is confidential and is for the exclusive 
attention of the planned recipient. If you have received the message by 
error, please notify the sender and delete the message without copying, 
recording or distributing it.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/f11dcd5f-deda-431d-91f2-5cbeb7bcff70n%40googlegroups.com.

Reply via email to