NetBeans 12.4 - Spring Boot Maven project, debug all test - spring-boot

In a Spring Boot Maven project I have tests with JUnit 5.
Within a test class (annotated with #SpringBootTest) I can select
Test File
Debug Test File
Run Focused Test Method
Debug Focused Test Method
On the project itself (Files window) I can select
Test
which runs all tests.
Is there a way to debug all tests?
So to speak I would expect a selection on the project like Debug Test besides Test.
The reason is, that some errors appear only when I run all tests. But when I run or debug just the erroneous test method or even the whole test class, the errors don't appear.

Sorry I haven't found a more GUI-friendly way yet (and verified only on Netbeans 12.3), but:
a) If you already have a nbactions.xml:
Add the following to the <actions/> element:
<action>
<actionName>CUSTOM-Debug-all-tests</actionName> <!-- should be unique for this project -->
<displayName>Debug All Tests</displayName> <!-- will be displayed in context menu -->
<packagings>
<packaging>*</packaging> <!-- according to your needs, taken from pre-configured action -->
</packagings>
<goals> <!-- according to your needs, taken from pre-configured action -->
<goal>process-test-classes</goal>
<goal>surefire:test</goal>
</goals>
<properties> <!-- according to your needs, taken from pre-configured action -->
<forkMode>once</forkMode>
<maven.surefire.debug>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}
</maven.surefire.debug>
<jpda.listen>true</jpda.listen>
</properties>
</action>
(Of course you can modify & adjust it to your needs, but this works for a quickstart (maven) project. Also interesting: "Debug integration test" action!)
Then you can execute it from "Project context menu>Run Maven>Debug All Tests"!
b) If You don't have an nbactions.xml (in your project) yet:
Just modify one of the pre-configured "Actions" (preferably "Debug (Integration) Test") from the "Actions" menu of "Project Properties", this (hitting "OK") will generate the according file at your project root. Then you can make it (maven-) executable as described above (a).(There must/should also be a way to run these Actions without modifying nbactions.xml at least by implementing a custom plugin....but haven't found the action/menu/tab yet:))

There is no need to modify the XML file directly, just
choose the Actions category in Project Properties
choose Configuration (<default config>, or dev (Profile), or...)
click Add Custom button
enter Action Name
fill the fields Execute Goals, Set Properties, etc.
If <default config> is choosen from Configuration, NetBeans will create a file nbactions.xml, otherwise if for example dev (Profile) is choosen a file nbactions-dev.xml is created, and so on.
The custom action is available in the context menue under Run Maven opened on pom.xml

Related

Alfresco Custom Content Type not showing

I have been trying to follow this tutorial about Alfresco custom content types
http://ecmarchitect.com/alfresco-developer-series-tutorials/content/tutorial/tutorial.html#localizing-strings-for-custom-content-models.
However, when I get to the 'Test your changes' step and I go to manage rules, I can't manage to get the custom types created (sc_doc and sc_whitepaper) in the dropdown list.
My share-config-custom.xml:
<!-- Share configuration related to this particular Share module extension, such as:
- Doclib action config
- Form config
- Aspect and Type config
Note. Any configuration related to the whole Share.war webapp
(i.e. not specific to this share extension) should be
placed in the environment specific config:
alfresco/tomcat/shared/classes/alfresco/web-extension/share-config-custom.xml file
-->
<alfresco-config>
<!-- Document Library config section -->
<config evaluator="string-compare" condition="DocumentLibrary">
<aspects>
<!-- Aspects that a user can see -->
<visible>
<aspect name="sc:webable" />
<aspect name="sc:productRelated" />
</visible>
<!-- Aspects that a user can add. Same as "visible" if left empty -->
<addable>
</addable>
<!-- Aspects that a user can remove. Same as "visible" if left empty -->
<removeable>
</removeable>
</aspects>
</config>
<config evaluator="node-type" condition="DocumentLibrary">
<types>
<type name="cm:content">
<subtype name="sc:doc" />
<subtype name="sc:whitepaper" />
</type>
<type name="sc:doc">
<subtype name="sc:whitepaper" />
</type>
</types>
</config>
</alfresco-config>
PS: Do I have to re-run 'mvn install' after every change I make in the .xml using Eclipse?
Any help will be much appreciated!
I know i am posting this answer bit late
and my solution is bit poor, But it works for me :)
I hope it will also work for you.
Strange thing is i am following same tutorial and at the time of 'Test your changes' stage not able to see my custom types on the server.
so to make it working in my share project i have changed place of
share-config-custom.xml
from src/main/resources/META-INF to src/main/amp/config/alfresco/web-extension
and restart alfresco and now able to view my custom types in type list on server.
plz post your answer if you have make done this by any other way :)
thank you.
I am not sure which kind of project you have created from maven artifacts.
Repository AMP archetype
All-In-One (AIO) archetype
Share AMP archetype
Here you can see list of all maven commands.
If you are not using local maven repository then you can go for "mvn package" to generate new AMP files and then deploy them manually on alfresco server.

Spring Tool Suite 3.7.0 not reading #ConfigurationProperties for content assist in YML

Hi I have move on to spring tool suite 3.7.0 with the highly anticipated feature of YAML editor as described here https://spring.io/blog/2015/06/30/spring-tool-suite-3-7-0-released specially the content assist that it provides .
The issue I am having is that my properties class as below
#ConfigurationProperties(prefix="datasource.ucp")
#Data
public Class DumbProperties{
private String url;
private String user;
...
}
does work but when I open my application.yml I still have to provide these manually the content assist doesnt work .ALso STS givem me a warning that the property doesnt exists .Screen shot below
ALso the maven entry for the same to find #ConfigurationProperties are added as below
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
anything I am missing here!!
Two things have to be in place for the configuration properties in your own source-code to work.
The "spring-boot-configuration-processor" must be on the classpath
The project must be confgure properly so that Eclipse JDT Annotation Processing is enabled to run the spring-boot-configuration-processor as part of an eclipse workspace build.
It sounds like you have 1. so probably its number 2. that's missing.
Normally, 2. should be configured automatically by STS, but it does this as part of m2e project configuration. If you just added the configuration-processor by pasting the xml into your pom, then its likely the project-configurator has not yet been executed. So try forcing it by selecting "Update Project" from the "Maven" context menu (accessed by right click on your project).
If that doesn't help, we'll have to troubleshoot a bit more as I don't know what's missing from your project's setup.

How to pass value to maven pom.xml at rum time from java file?

I have a java file where a variable taken value at run time.I search for a service using web service discovery and keep its url in a variable.
Now I need to pass this value to pom.xml.
abc.java has code with
String url= http://xx.xx.xx.xx:55939/ABCDevice?wsdl
Pom.xml is:
<wsdlOptions>
<wsdlOption>
<wsdl>url</wsdl> <!-- get urlvalue from java file -->
<wsdlLocation>classpath:com/admin/discovery/ABCService.wsdl
</wsdlLocation>
</wsdlOption>
</wsdlOptions>
In wsdl i want to pass string value "http://xx.xx.xx.xx:55939/ABCDevice?wsdl" which is determined only after run time.
How can i do so ?
I don't consider this as an Apache Maven specific issue, but a general Java issue (Maven probably made you aware of it).
During build-time you have no idea what the url should be. Depending on the type of application you have several options:
JNDI (in case of a webcontainer)
A properties file on a predefined location
System properties
As arguments (in case of executable jar)
Adjust web.xml before deploying (some webcontainers can help you with this)
...
In you use a framework like Spring there are easy ways to inject one the options above.

Maven PDF Plugin custom properties are not filtered in the generated PDF

I am trying to generate a PDF and the main generation works fine, but I face the issue trying to use custom defined properties.
I do have the my properties defined in pom.xml as documented, but when I use them in the content files in the final result I don't see them substituted, but staying with the variable i.e ${myProperty}.
e.g. I have the property defined in pom.xml
<properties>
<myProperty>My other value</myProperty>
</properties>
If I use the same property in pdf.xml it is being properly substituted(i.e on the title tah), but if I
set it in an .apt.vm file as ${myProperty} it doesn't.
The apt file is also with .vm extension as documented on the site.
On the other hand system properties as ${project.name} work fine.
Do you have an idea what am I missing?

How do I control spring injections that vary between the test environment and the production environment?

I'm setting up a CI situation in which I will deploy my web app to a test environment. In this test environment, I want the business objects used by the app to be mocks of the real ones; the mocks will return static test data. I'm using this to run tests agains my ui. I'm controlling the injections of these business object dependencies with Spring; it's a struts 2 application, for what that's worth.
My question is Maven related, I think. What is the best way to have my Maven build determine whether or not to build the spring configuration out for injecting the mocks or injecting the real thing? Is this a good use for maven profiles? Other alternatives?
Spring itself has support for profiles (if you're using 3.1 or newer), for a web-application you can use context-parameter to set the active profile for different environments in the web.xml:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>test</param-value>
</context-param>
Edit: For Maven & Jenkins, you should be able to set the parameter for a build job as follows:
First, let Maven filter your xml-resources (in this example, only files ending with xml are filtered, others are included without filtering) by adding the following into your pom.xml inside the <build> </build> -tags:
<resources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/*xml</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*xml</exclude>
</excludes>
</resource>
</resources>
Then, parameterize the context-param in your web.xml:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>${env.SPRINGPROFILE}</param-value>
</context-param>
Then parameterize the build job in Jenkins to set the desired string parameter for SPRINGPROFILE (for example test or prod): https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build
It's probably a bad idea to do anything with the build of the web app artifact ( Maven best practice for generating artifacts for multiple environments [prod, test, dev] with CI/Hudson support? ). While you could use various mechanisms to produce a WAR file with different configurations of the Spring injections for different contexts, the WAR artifact should be the same every time it's built.
In order to extract the configuration out of the WAR, I have used Spring 3's ability to pull in override values from an external property file. I define default, i.e. produciton, values of my business objects. And I configure spring to check for the existence of a properties file, something I will deploy when the app is in a testing environment and requires mock injections. If that properties file exists, it's values are injected instead. Here's the relevent bit of the spring config file.
<!-- These are the default values -->
<util:properties id="defaultBeanClasses">
<prop key="myManagerA">com.myco.ManagerAImpl</prop>
<prop key="myManagerB">com.myco.ManagerBImpl</prop>
</util:properties>
<!-- Pull in the mock overrides if they exist. -->
<context:property-placeholder
location="file:///my/location/mockBeans.properties"
ignore-resource-not-found="true"
properties-ref="defaultBeanClasses"/>
<!-- The beans themselves. -->
<bean id="managerA" class="${myManagerA}"/>
<bean id="managerB" class="${myManagerB}"/>
And here is the contents of the external "mockBeans.properties" file:
#Define mock implementations for core managers
myManagerA=com.myco.ManagerAMockImpl
myManagerB=com.myco.ManagerBMockImpl
This works nicely. You can even include the mockBeans.properties file in the actual WAR, if you like, but not in the live location. Then the test environment task would be too move it to the location pointed at by the spring config. Alternatively, you could have the mock properties reside in a completely different project.

Resources