Strange JUnit/Google Endpoint test result - java

I have the below test method to test the creation of the Partner entity in Objectify datastore.
I got the DuplicateRecordException as excepted, but when I try to retrieve the entity (any entity in that Class) and I got a null. Any idea what I missed?
NOTE: I launched the local API explorer to test the createPartner() method and it just fine.
#Test
public void testCreatePartner(){
try {
Partner p = createPartner(instID, displayName, new Text(aboutMe));
createPartner(instID, displayName, newText(aboutMe));
assertNull(p);
} catch (DuplicateRecordException | MissingIDException | FailToSaveRecordException e) {
//e.printStackTrace();
log.severe("======> "+e.getMessage());
Partner q = OfyController.ofy().load().type(Partner.class).first().now();
if (q!=null) {
log.info("------>>" + q.getDisplayName());
}
}
}

Solved it!
I also had this:
new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(100)
I change 100 to 1 and it worked.

Related

Jsoup not connecting to webpage in Android Studio

I am working on a project right now where I use jsoup in a class with the function retrieveMedia in order to return an ArrayList filled with data from the webpage. I run it in a thread since you shouldn't be connecting to URLs from the main thread. I run it and join it. However, it doesn't work (I tested the same code in Eclipse separate from Android Studio and it worked fine). It seems that no matter what I do I can't get jsoup to connect to the webpage. Below is my class MediaRetriever.
public class MediaRetreiever {
public ArrayList<Media> retrieveMedia() {
ArrayList<Media> mediaOutput = new ArrayList<Media>(); //Store each scraped post
Thread downloadThread = new Thread(new Runnable() {
public void run() {
Document doc = null;
try {
doc = Jsoup.connect(<Website Im connecting to>).timeout(20000).get();
} catch (IOException e) {
System.out.println("Failed to connect to webpage.");
mediaOutput.add(new Media("Failed to connect", "oops", "", "oh well"));
return;
}
Elements mediaFeed = doc.getElementById("main").getElementsByClass("node");
for (Element e : mediaFeed) {
String title, author, imageUrl, content;
title=e.getElementsByClass("title").text().trim();
author=e.getElementsByClass("content").tagName("p").select("em").text().trim();
content=e.getElementsByClass("content").text().replace(author,"").trim();
Media media = new Media(title, author, "", content);
mediaOutput.add(media);
}
}
});
downloadThread.start();
try {
downloadThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
return mediaOutput;
}
}
Running this class's method from another class and it doesn't ever connect. Any ideas?
Since you say that the problem persists only in Android, it looks like that you should add the user agent string to your request - first get the user agent string of a browser that displays correctly the site, and then add it to the request:
doc = Jsoup.connect(<Website Im connecting to>)
.userAgent("your-user-agent-string")
.timeout(20000).get();
And as a sidenote - if you are catching exception, don't print your own error message - print the original message, it may be very useful.

Spring JPA Crud Repository save() not updating entity

In my code i am trying to update my entity but data is not getting saved in db.
checked logs there is no exception as well.
Also tried #Transaction annotation but it doesn't work.
Method for save call
public void uploadBill(Long quoteId, MultipartFile multiPartFile) {
try {
ServiceQuote serviceQuote = serviceQuoteRepository.findOne(quoteId);
String extension = "";
if (multiPartFile.getOriginalFilename().lastIndexOf(".") != -1) {
extension = multiPartFile.getOriginalFilename().substring(
multiPartFile.getOriginalFilename().lastIndexOf("."),
multiPartFile.getOriginalFilename().length());
}
String filename = SERVICING_BILL_FILE_PREFIX
+ serviceQuote.getReferenceNo() + extension;
filename = AmazonS3Util.uploadBill(multiPartFile, filename);
serviceQuote.setBillPath(filename);
serviceQuoteRepository.save(serviceQuote);
} catch (Exception e) {
e.printStackTrace();
}
}
Here serviceQuoteRepository is JPA crud repositorty
#Repository
public interface ServiceQuoteRepository extends CrudRepository<ServiceQuote, Long> {}
Please suggest what could be possible fix.
There was no issue related to crud repository. Actually after upload method another service was updating the entity with null bill path at the same time so I was seeing the null column always. Figured out after debugging the issue for few hours.

Customized selenium Output

Am working on selenium Automation
I want to know the name of which elements is not found when test cases got failed instead of getting object not found with property By.id("Login")
am expecting output like Object not found LoginButton(Customized name which i will give in code) when test cases fails due to defect
public static void logonCustomerPortal() throws Exception{
Thread.sleep(5000);
driver.findElement(By.xpath("//a[#id='nav_login']/span")).click();
Thread.sleep(2000);
}
I am new to Automation. Can anyone please help me ?
try to use try catch like this :
public void urmethod(){
try {
//do your code
}catch (Exception e){
e.printStackTrace();
}
}
this will print details of your error, in other words, what kind of error, in which line it fails...etc

Parse: How can I get Relation from a local data store (...fromLocalDatastore())?

I am developing an app to serve as a learning and I'm using Parse (parse.com) as a data source.
I am conducting download all objects of my classes in the parse and saving to a local store that has Parse. The following code snippet that performs one of downloads:
public void noticia_getOrUpdate(boolean isUpdate) throws ParseException {
ParseQuery<Noticia> query = new ParseQuery(Noticia.class);
query.orderByDescending("createdAt");
List<Noticia> lNoticias = null;
try {
if (isUpdate) {
lNoticias = query.whereGreaterThan("updatedAt", this.sPref.ultimaAtualizacao_noticia()).find();
if (!lNoticias.isEmpty())
ParseObject.pinAllInBackground(lNoticias);
} else {
query.whereEqualTo("ativo", true);
lNoticias = query.find();
for (Noticia noticia : lNoticias) {
if (noticia.getUpdatedAt().getTime() > this.sPref.ultimaAtualizacao_noticia().getTime())
this.sPref.atualiza_noticia(noticia.getUpdatedAt());
}
ParseObject.pinAllInBackground(lNoticias);
this.sPref.atualiza_isUpdate(true);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
The problem is I'm downloading all my classes, one is the File type, is a file that works as an image for my news ("Noticia"). I can download and store all on-site data storage, but can not recover using the following code:
public static byte[] NoticiaMidiaRelation(Noticia noticia) {
try {
ParseRelation<Midia> relation = noticia.getImagem();
Midia midia = relation.getQuery().fromLocalDatastore.whereEqualTo("ativo", true).getFirst();
if (midia != null && midia.getFileData() != null)
return midia.getFileData();
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
If retreat the "fromLocalDatastore" the query, he seeks the server and brings the file correctly, but do not want to pursue it again, because as said, already have the same image stored in the local data store.
Another way to do would be to get the relationship the media Id, after that perform a search for comparing ObjectId within the local store, but I think there's no way the property "parent". But if any, can be used as a solution.
You can't according to the documentation:
By default, when fetching an obj
ect, related ParseObjects are not fetched
There are work arounds but they might not be practical because by what I understand, you only have one image in your relation per ParseObject in your "Notica" class as you call getFirst(). In this case, using a Pointer would be a better decision but those aren't fetched by default either BUT they are cached to the LocalDatastore. You'll need to add the following code to your query to fetch the Pointer object.
query.include("your_column_key");

image is not showing in java in compiler

I am working on a java code and my image is not shown in the final run. I put it in an entity and I also handed the entity over to the entity manager. Eclipse is not showing me any problem, but when I go to run I can not see my image only the background I did wrote before.
Any suggestions on how to fix it?
The following is the part for my code:
private void gorilla() {
Entity gorilla1 = new Entity("gorilla1");
gorilla1.setPosition(new Vector2f(590, 190));
try {
gorilla1.addComponent(new ImageRenderComponent(new Image("assets/gorillas.gorillas/gorilla_right.png")));
} catch (SlickException e) {
System.err.println("Cannot find file gorilla_right.png!");
e.printStackTrace();
}
entityManager.addEntity(stateID, gorilla1);
}

Categories