NoClassDefFoundError: in jenkins-test-harness-htmlunit library - unit-testing

I am developing test cases for one of my plugin. Below is snipped code of test case:
JenkinsRule.WebClient webClient=rule.createWebClient();
FreeStyleProject p = (FreeStyleProject) rule.jenkins.getItem("WebApp");
HtmlPage page= webClient.getPage(p,"configure");
.
I am always getting java.lang.NoClassDefFoundError: Could not initialize class com.gargoylesoftware.htmlunit.util.EncodingSniffer . I have checked dependency jenkins-test-harness-htmlunit and it has same class.
I am having below jenkins and jenkins-test-harness version in my plugin:
<properties>
<jenkins.version>2.7.3</jenkins.version>
<java.level>8</java.level>
<jenkins-test-harness.version>2.27</jenkins-test-harness.version>
</properties>
Please help me if anybody has solution for it

Related

Item Template for VSTemplate file

I'm trying to create VS Item Template that will allow adding .vstemplate files to project.
This is how my vsTemplate.vstemplate file currently looks:
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate
xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"
Version="3.0.0"
Type="Item">
<TemplateData>
<Name>VS Item Template</Name>
<Icon>vsTemplate.ico</Icon>
<Description>VS Item Template Files</Description>
<DefaultName>vsTemplate</DefaultName>
<ProjectType>CSharp</ProjectType>
<TemplateID>Microsoft.CSharp.Class</TemplateID>
<CreateInPlace>true</CreateInPlace>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="Template\$fileinputname$.vstemplate" ReplaceParameters="true">vsTemplate.data</ProjectItem>
<ProjectItem TargetFileName="Template\$fileinputname$.$fileinputextension$.data">vsTemplate.empty.data</ProjectItem>
<ProjectItem TargetFileName="Template\$fileinputname$.ico">vsTemplate.ico.data</ProjectItem>
</TemplateContent>
</VSTemplate>
When I am trying to use it (inside vs experimental instance), I am getting this error:
The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
How I understand the problem, I need to specify custom build action for .vstemplate file inside .csproj file, something like this:
<VSTemplate Include"..."/>
But I don't know how to do that.
What I'am already tried:
set ItemType="VSTemplate" for vstemplate ProjectItem
use custom Wizard class
add /log option inside project command line argument window (it does not provide any additional information)

Django 1.6 test discovery cannot find test modules

Django 1.6.10 cannot find test modules located outside my apps when running any of these code (ref: https://docs.djangoproject.com/en/1.6/topics/testing/overview/#running-tests)
./manage.py test tests/app1/
./manage.py test tests/app1/test_views
I keep getting these errors
django.core.exceptions.ImproperlyConfigured: App with label tests/app1/ could not be found
django.core.exceptions.ImproperlyConfigured: App with label tests/app1/test_views could not be found
Here is my project structure:
- project
- app1
- __init__.py
- models.py
- views.py
- forms.py
- admins.py
- app2
- ..as per above
- tests
- __init__.py (blank)
- app1
- __init__.py (blank)
- test_views.py
- test_forms.py
- app2
- __init__.py (blank)
- test_views.py
- test_walkthrough.py
I read Django Discovery runner a few times and still cannot find out where did I go wrong. Any help please - what do I miss
Replacing / with . gives the same error however when execute
./manage.py test tests.app1.test_views.MyTestCase
./manage.py test tests.app1.test_views.MyTestCase.test_mymethod
I get ValueError.
ValueError: Test label 'tests.app1.test_views.MyTestCase.test_mymethod' should be of the form app.TestCase or app.TestCase.test_method
Further update:
I finally got it to work when adding --testrunner='django.test.runner.DiscoverRunner' to the command line. As per Django doc, any of these patterns works now (using / is a way of providing a path to a directory to discover tests below that directory):.
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests.app1
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests.app1.test_views.MyTestCase
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests/app1/
Still do not know why I have to provide --testrunner value. I am using Mezzanine in my code too and have double confirmed that settings.TEST_RUNNER is pointing to django.test.runner.DiscoverRunner
Can anyone help explaining why do I need --testrunner flag in django 1.6? Thank you in advance.
You should be referring to them as modules, not paths:
./manage.py test tests.app1
./manage.py test tests.app1.test_views
Read more about running tests in the docs.

Plone 4.3.x - grokcore.view - UserWarning: Found the following unassociated template after configuration

On a vanilla Plone 4.3.3 site (Unified Installer on Ubuntu 14.04.1LTS), and after updating buildout.cfg with the zopeskel and paster boiler plate stuff and running buildout, I successfully created a dexterity package in my src folder:
$ cd src
$ ../bin/zopeskel dexterity my.package
After updating buildout.cfg (adding my.package to the eggs section and src/my.package to the develop section) and running buildout, I added content to my new package:
$ cd my.package
$ ../../bin/paster addcontent dexterity_content
I called the new content type mytype, resulting in mytype.py, a templates folder called mytype_templates, etc.
Restarting Plone and.... so far, so good....
Then I add templates to the mytype_templates folder:
add.pt
edit.pt
view.pt
In the mytype.py file I added all the necessary imports, schema definition
Class Imytype(form.Schema, IImageScaleTraversable):
....
....
, etc, etc, and obviously also the view, add and edit classes:
class View(dexterity.DisplayForm):
grok.context(Imytype)
grok.require('zope2.View')
# Disable turn fieldsets to tabs behavior
enable_form_tabbing = False
def update(self):
super(View, self).update()
class Add(dexterity.AddForm):
grok.name('my.package.mytype')
# Disable turn fieldsets to tabs behavior
enable_form_tabbing = False
def __init__(self, context, request):
super(Add, self).__init__(context, request)
......
......
class Edit(dexterity.EditForm):
grok.context(Imytype)
# Disable turn fieldsets to tabs behavior
enable_form_tabbing = False
def update(self):
super(Edit, self).update()
......
......
When I restart my Plone site in foreground mode, I get the following messages:
2015-02-06 12:52:41 INFO ZServer HTTP server started at Fri Feb 6 12:52:41 2015
Hostname: 0.0.0.0
Port: 8080
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/edit.pt
warnings.warn(msg, UserWarning, 1)
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/add.pt
warnings.warn(msg, UserWarning, 1)
2015-02-06 12:52:46 INFO Zope Ready to handle requests
Seemingly grok successfully picks up the view.pt, but not the add.pt and edit.pt
This is confirmed by customizing the templates. Changes to view.pt renders fine, changes to add.pt and edit.pt have no results. Plone falls back on the default dexterity templates, as the add.pt and edit.pt are not grokked.
I found a work-around by adding the following:
....
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
....
and to the Add class:
template = ViewPageTemplateFile('mytype_templates/add.pt')
and to the Edit class:
template = ViewPageTemplateFile('mytype_templates/edit.pt')
Obviously the error messages as listed above are still there, but at least it works and I can customize the add.pt and edit.pt.
Although I can live with this workaround, I am wondering why only the view.pt is grokked and not the add.pt and edit.pt.
Please notice that this (weird?) behavior was also duplicated using Plone 4.3.1, 4.3.2, 4.3.3 and 4.3.4
Any suggestions?
You have to declare the name, context, layer and schema of the views; use something like this (note the grok.layer method which maybe you're missing):
class AddForm(dexterity.AddForm):
grok.name('my.package.mytype')
grok.layer(Imylayer)
grok.context(Imytype)
schema = Imytype
def update(self):
super(AddForm, self).update()
...
class EditForm(dexterity.EditForm):
grok.context(Imytype)
grok.layer(Imylayer)
schema = Imytype
def update(self):
super(EditForm, self).update()
...
Alternatively you may skip the use of Grok at all and register everything via ZCML.
An example of this can be found in the collective.nitf package. There's a branch using Grok and a pull request removing it.

Django is ignoring my TestCase fixtures

I've got Django 1.4. In my test.py, I've got the requisite TestCase import:
from django.test import TestCase
To isolate the issue, I've added the line:
fixtures = ['westeros']
to the default example test case, i.e.
class SimpleTest(TestCase):
fixtures = ['westeros']
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
Using django-admin.py dumpdata, I created a fixture file called "westeros" in my customers/fixtures directory, where "customers" is an app that is listed in settings.INSTALLED_APPS.
When I run the test, at any verbosity, Django simply ignores the fixture and passes the test_basic_addition test. No error, no fixture loading. It's as if the TestCase import isn't there. Any ideas on what could be wrong or how to debug this?
It's ok to omit the extension when defining fixtures as you have done, i.e.
fixtures = ['westeros']
However, the fixture file itself must have the extension that corresponds to its serializer e.g westeros.json, westeros.json.zip or westeros.xml for json, zipped json or xml respectively.
Where is your westeros file located?
It needs to either be in a fixtures directory inside an app or in the dir specified by FIXTURE_DIRS in your settings.py file
You can run with tests with verbosity=2 to get full output.
https://docs.djangoproject.com/en/1.0/ref/django-admin/#test
Is your fixtures file named westeros ? or does it have a file extension?
Django will fail silently on fixture loads as you see. (at least up until 1.3, I haven't used fixtures in new 1.4 version yet). But you are not actually testing if the fixtures are loading.
Throw in a self.assertGreater(YourModel.objects.all(), 0) or somethign to verify that there are no objects, or drop in a debbuger and start querying some of your models.

Solr Admin not found: "missing core name in path"

I'm running solr on dotcloud for my django app (using haystack) and am running into some trouble. I receive a 404 "missing core name in path" message when trying to access the admin, despite the fact that--as far as I can tell--I only have a single core.
Here is my schema.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<!--
adminPath: RequestHandler path to manage cores.
If 'null' (or absent), cores will not be manageable via request handler
-->
<cores adminPath="/admin/cores" defaultCoreName="collection1">
<core name="collection1" instanceDir="." shard="shard1"/>
</cores>
</solr>
When I point my browser at .../solr/collection1/admin, still nothing. But since I've only got a single core shouldn't I just be able to go to .../solr/admin?
I've followed the steps on the haystack "getting started tutorial" as well as the dotcloud solr service docs.
The relevant code in my settings.py:
HAYSTACK_SITECONF = 'gigmash.search_sites'
HAYSTACK_SEARCH_ENGINE = 'solr'
HAYSTACK_SOLR_URL = 'http://35543365.dotcloud.com/solr' #provided by dotcloud
HAYSTACK_INCLUDE_SPELLING = True
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 10
And here's the error I get when I try and test in the interpreter:
>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().all()
>>> sqs.count()
Failed to query Solr using '*:*': [Reason: None]
java.lang.NullPointerException at org.apache.solr.servlet.SolrServlet.doGet(SolrServlet.java:91) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:297) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
I find it especially amusing that my error output says "reason: none" :-P
Perhaps also relevant: despite having run ./manage.py build_solr_schema and ./manage.py rebuild_index (and having rebuild index (accurately) report the number of models indexed), a data/ directory has not been created in my solr/ directory.
Any help would be greatly appreciated. Total newb with solr/haystack/dotcloud/everything!
Solved.
It ended up being an issue with my dotcloud.yml file.