I'm a bit fan of Google's Truth.dev library. I have a large domain model in Java, and want to add several little custom assertions for them in my own Subject files. It's a bit of pain though to create the boiler plate for the Subjects every time though, and there are lot's obvious / straight forward assertions that I'd like to have by default.
Something similar to AssertJ's generator project.
For example, given the following simple model (mine is much more complicated):
#lombok.Value
public class Car {
String name;
Make make;
int colourId;
public enum Make {PLASTIC, METAL}
}
I would like to be able to do the following without coding anything myself:
assertThat(car).hasMakeEqualTo(PLASTIC);
assertThat(car).hasColourId().isAtLeast(5);
assertThat(car).hasName().ignoringTrailingWhiteSpace().equalTo("sally");
or
assertThat(person).hasAddress().hasStreet().ignoringCase().endsWith('Rd')
Upon my discovery of the lovely Google Truth, I was an instant convert from AssertJ. However I didn't like the boiler plate required to the get the full potential out of it. I also had just found AssertJ's code generator. So I made one for Google Truth.
You can find out everything about it on it's GitHub page.
Assertion failures for the assertions in the stated question with Truth look like:
assertThat(car).hasName().ignoringTrailingWhiteSpace().equalTo("sally");
value of: car.getName().
expected: sally
but was : yuYU3KZU3c
car was : Car(name=yuYU3KZU3c, make=METAL, colourId=420434249)
assertThat(car).hasMakeEqualTo(PLASTIC);
expected Make to be equal to: PLASTIC
but was : Car(name=7lvPSNeMJj, make=PLASTIC, colourId=1732244871)
assertThat(car).hasColourId().isAtLeast(8);
value of : car.getColourId()
expected to be at least: 8
but was : 5
car was : Car(name=oYZIeRofZn, make=PLASTIC, colourId=5)
To achieve the above, you simply add it to your build.
<plugin>
<groupId>io.stubbs.truth</groupId>
<artifactId>truth-generator-maven-plugin</artifactId>
<configuration>
<classes>
<param>io.stubbs.truth.generator.example.Car</param>
</classes>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
It is very powerful and flexible. Very keen to get feedback and implement more ideas.
Related
How do you remove the ability to find content under language identifiers in Sitecore?
Content here:
/about
Is also available at:
/en/about
Weirder yet, any attempt to find content under a different language identifier results in an error about not being able to find Views.
/es/about
/pt-br/about
/aa/about (this is invented..)
I don't want content available under any language identifier -- the URLs above should simply be 404s.
I can't find where this language identifier is isolated and processed. I removed the LanguageResolver from the httpRequestBegin pipeline, but this didn't change the behavior.
There are many blog posts about turning off language embedding in the LinkManager, which I've done, but that's not enough -- I do not want content being produced under any language code. The firs segment of the URL should be treated like any other segment. Requests for /en/[whatever] should 404.
As well as setting the LinkManager to never embed, you also need to set the Languages.AlwaysStripLanguage setting to false.
Source: http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2015/03/prevent-the-sitecore-aspnet-cms-from-interpreting-url-path-prefixes-as-language-names.aspx
Assuming you already have a custom 404 resolver in place, you just need to change the Sitecore setting Languages.AlwaysStripLanguage from true to false like so:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Languages.AlwaysStripLanguage" value="false" />
</settings>
</sitecore>
</configuration>
when we implement SitecoreApiController, for each action method we make using Sitecore.Services.Core.ServicesController("namespace") attribute, we get a url like this:
/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}
I wonder if we could change this default pattern, somehow in config files. I particularly interested in /sitecore/api/ part, because sometimes in the sense of security concerns, certain clients don't like to reveal that much about CMS platform behind the scene. Sometimes they even ask us to hide anything in HTTP header that tells about Microsoft ASP.NET explicitly.
Is this possible here?
Edit
this link shows a way to customize it using pipelines but I wonder if we could change the base url just through config files without needing a custom pipeline
I had a look at it, and I think I found out how - although I haven't tested it.
It looks for a setting named Sitecore.Services.RouteBase and if it can't find it, it uses sitecore/api/ssc/ as the default value.
You should be able to change it with a config patch like this in the App_Config/Include folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Sitecore.Services.RouteBase" value="custom/api/" />
</settings>
</sitecore>
</configuration>
I need Maven to include every dependency that has a specific groupId, version and type (for example only wars). Is it possible? Is there any plugin for this? Any pattern expression?
Something like this that I can do in my pom.xml:
<dependency>
<groupId>an.exact.group.id</groupId>
<!-- No artifactId specified-->
<version>*-SNAPSHOT</version> <!-- a pattern here for version -->
<type>war</type>
</dependency>
I don't want exactly like the above code. But, the result I wish is to have in the classpath all the artifactIds that respect the mentionned tags.
Thank you a lot!
Not sure how to do it from POM directly but you can always create a java main class, read your pom , append the necessary dependencies , and the print out a new POM file with all the details.
Use rest api to get the details on the versions.
http://search.maven.org/#api
e.g.
http://search.maven.org/#search|gav|1|g:"com.google. inject"%20AND%20a:"guice"
Mimics clicking the link for all versions of groupId "com.google. inject" and artifactId "guice." Returns sorted list of all versions of an artifact.
I have a problem using the Maven Plugin Testing Harness (2.0-alpha1): When I want to test my Mojo, the default values and expressions for parameters are not applicable.
I have the following parameter:
/**
* <p>The output file to write the settings to.</p>
*
* #parameter default-value="${project.build.directory}/myProperties.properties" expression="${properties.file}"
*/
private String file;
When I run my unit tests this property is always null. I tried to inject a MavenProjectStub which returns ${project.build.directory} successfully but this is not applied to my Mojo parameter.
Is there any way to enable default values and expressions like ${project.build.directory} inside my Mojos during the tests?
So it looks like they added lookupConfiguredMojo for just this use case. It took me a while to figure out how to call that because you need a properly configured MavenProject to use it. Here's what worked for me:
File pomFile = ...
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
MyMojo mojo = (MyMojo) this.lookupConfiguredMojo(project, "my-goal");
...
I hit a bunch of issues including this when testing my plugin. Each problem only took a few lines to fix but finding them wasn't easy. The pointers here helped!
I've combined them in a
BetterAbstractMojoTestCase.java class. It contains the magic lines which solved the half-dozed issues I hit; and it gives a lookupConfiguredMojo(File pom, String goal) method for your issue here.
I've had this very same problem and couldn't find any solution, so I decided to fix it myself. I've checked out the source code for the latest version of the maven-plugin-testing-harness (which is 2.0-alpha-1 at the moment) and placed it in my own github repository.
You will have to checkout the code from there and build it locally.
The only change you need to make in your project is replace the dependency in your POM. I used my own domain/groupId name instead of the Apache one just to avoid any conflicts (and confusion) with future Apache releases.
This is what you need to put in your POM:
<dependency>
<groupId>com.menttis.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
And this is the repository where you can grab the code from: https://github.com/grighetto/maven-plugin-testing-harness
For version 3+:
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5</version>
<scope>provided</scope>
</dependency>
spent a while confused about this myself before realising I was mixing the annotation syntax with the javadoc syntax.
#Parameter(property = "project.build.directory")
private String projectBuildDir;
Then concatenate your file name with that value to complete the path in your code.
We're experiencing a problem building templates in Word 2010 that feature Content Controls. These templates are used in conjunction with a custom system we have inherited that uses them to build reports.
These templates feature nested Content Controls thus:
<CONDITION>
<IF>{xpath}</IF>
<THEN>
{rich text}
</THEN>
</CONDITION>
The IF is used to determine whether a condition specified via an {xpath} is true or false. If it is true the content contained within the THEN control is then used.
The odd thing is there doesn't seem to be a problem building the templates. When they are saved they work fine in the custom system. However, when they are later re-opened in Word 2010, the {rich text} that was suppose to appear in the THEN Content Control is replaced with the {xpath} from the IF Content Control thus:
<CONDITION>
<IF>{xpath}</IF>
<THEN>
{xpath}
</THEN>
</CONDITION>
As the templates work with the system it seems like this corruption occurs at the point where they are re-loaded into Word 2010. As such, it seems like the first time we'll get to know about this corruption is when someone reloads the template to make further alterations, days, weeks or many months later. By which time we may have forgotten what should be there and lost an awful lot of work.
Can anyone explain why this corruption might be happening?
I've looked on the internet for an answer but found nothing.
It sounds like there is a mistake in your code causing malformed XML. When opened, Word tries to interpret the malformed XML and as a result you are ending up with undesired results.